linux commands Flashcards

1
Q

How do you connect to bandit.labs.overthewire.org on port 2220 with the username bandit0?

A

ssh bandit0@bandit.labs.overthewire.org -p 2220

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Standard Unix/Linux command used to check the information of disk usage of files and directories on a machine?

A

du

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are two ways to read a file named ‘-‘ ?

A
  1. cat
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you read a file that has spaces in the filename?

A

place the filename in single quotes

EX: cat ‘spaces in the filename’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you display hidden files in a directory?

A

ls -a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you connect to bandit.labs.overthewire.org on port 2220 with the username bandit0, and using a password stored in a file named “bandit0”?

A

sshpass -p ‘cat bandit0’ ssh bandit0@bandit.labs.ovedrthewire.org -p 2220

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would you determine the types of files in a directory named “inhere” that all start with “-“?

A

file ./*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How would you read all the contents of every file within a directory named “inhere” that all start with “-“?

A

strings ./*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How would you search all subdirectories of the current directory for a file that matches the following characteristics:

  • human-readable
  • 1033 bytes in size
  • not executable
A

find ! -executable -size 1033c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How would you search the entire server for a file that matches the following characteristics, and do not show any permission denied errors (should only return one file):

  • owned by user bandit7
  • owned by group bandit6
  • 33 bytes in size
A

find / -size 33c -user bandit7 -group bandit6 2>/dev/null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Search the file “data.txt” for the line with the word “millionth”.

A

cat data.txt | grep millionth

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you search the file “data.txt” for the line of text that appears only once.

A

cat data.txt | sort | uniq -c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

After using this above command (cat data.txt | sort | uniq -c) to sort the file “data.txt” for unique lines, you have a bunch of lines that occur 10 times (shows 10 at the start of the line) and one line that occurs once. How can you remove all of the lines that start with ‘10’ to only leave the line that starts with ‘1’?

A

cat data.txt | sort | uniq -c | grep -v “10”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Search the file “data.txt” for the few human-readable strings that begin with several ‘=’ characters.

A

strings data.txt | grep “=”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the sign that something is Base64 encoded?

A

The string ends in 0, 1, 2, or 3 “=” sign

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you decode the string of data within the file “data.txt” that is Base64 encoded?

A

cat data.txt | base64 -d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you get a password from the file data.txt, with a string where all lowercase (a-z) and uppercase (A-Z) letters have been rotated by 13 positions?

A

cat data.txt
– displays the text “Gur cnffjbeq vf 5Gr8L4qetPEsPk8htqjhRK8XSP6x2RHh”–
echo “Gur cnffjbeq vf 5Gr8L4qetPEsPk8htqjhRK8XSP6x2RHh” | rot13

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How do you take a hexdump file and reverse the hexdump process to a readable file?

A

xxd -reverse data.txt > newfile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How do you uncompress the file “data.gz”?

A

gunzip data.gz

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do you uncompress the file “data.bz2”?

A

bunzip2 data.bz2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How do you uncompress a file “data.txt” that is a POSIX tar archive file type?

A

tar xf data.txt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How do you ssh to ‘localhost’ with user bandit14 using the key “sshkey.private” located in the current directory?

A

ssh -i sshkey.private bandit14@localhost

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How do you netcat a password that is in /etc/bandit_pass/bandit14 to port 30000 on localhost?

A

cat /etc/bandit_pass/bandit14 | nc localhost 30000

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How to list all contents, including permissions, and hidden files of the current directory?

A

ls -la

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

How do you make a python file named file.py executable?

A

chmod +x file.py

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

How would you make “foobar” provide the same results in the command line as “ls -la”?

Where would you make the change in order for it to persist after reboot?

A

alias foobar=’ls -la’

make ~/.bashrc to make it persist after reboot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

How do you write text to a file?

A

echo Hello World > peanuts.txt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

How do you write text to a file, without deleting any existing text (append new text to the end of the existing file)?

A

echo Hello World&raquo_space; peanuts.txt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is the file descriptor for stdin, stdout, and stderr?

A
  • stdin = 0
  • stdout = 1
  • stderr = 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

How would you redirect the standard error of “ls /fake/directory” to a special file that will discard any input?

A

ls /fake/directory 2> /dev/null

31
Q

What does the pipe operator “|” do?

A

allows us to get the stdout of a command and make that the stdin to another process.

32
Q

How would you write the output of “ls -la /etc” to a file and to the screen?

A

ls -la /etc | tee file.txt

33
Q

How do you display the first 10 lines of file.txt?

A

head file.txt

34
Q

How do you see the last ten lines of file.txt?

A

tail file.txt

35
Q

How do you get the unique values of a file?

A

uniq -u file.txt

36
Q

How would get the number of times a line appears in a file?

A

uniq -c file.txt

37
Q

How would you get lines that are duplicated in a file?

A

uniq -d file.txt

38
Q

What information about a file does “wc” provide?

A
  • number of lines
  • number of words
  • number of bytes
39
Q

How would you fine all of the instances of the word “Hello” in file.txt?

A

grep Hello file.txt

40
Q

How would you list all of the files in the /etc directory with “.conf” extension?

A

ls /etc | grep .conf

41
Q

How would you print all of the lines of file.txt that begin with “Hello”?

A

grep ^Hello file.txt

42
Q

How would you print all of the lines that end with “seahorse”?

A

grep seahorse$ file.txt

43
Q

How would you print all of the lines that start with the letter “H” in file.txt?

A

grep H. file.txt

44
Q

How would you print all of the lines that start with either “dig”, “dug”, or “dog” in file.txt?

A

grep d[iou]g file.txt

45
Q

How would you print the lines that start with “dog” and “dug”, but not “dig”?

A

grep d[^i]g file.txt

46
Q

Using the vim editor, how do you find all instances of the word “Hello”, and how do you advance through each instance of “Hello” found in the file?

A
  • /Hello
  • press ‘n’ to advance forward
  • press ‘N’ to go backwards
47
Q

Print the relative file paths, one path per line for all filenames that start with “access.log” in the current directory.

A

ls acc*

48
Q

How would you find all files in the current directory and all subdirectories that are of the type “file”?

A

ls . -type f

49
Q

How do you print all the files in the current and subdirectories that have the word “access” in the filename and the text “500” in them?

A

find -name “access*” -exec grep -h ‘500’ { } \;

50
Q

Extract all IP addresses from files (recursively, all subdirectories) that start with “access.log” printing one IP address per line.

A

find . -type f -name “access.log*” -exec grep -oE

51
Q

Regex for IP address?

A

([0-9]{1,3}.)[0-9]{1,3}

52
Q

Extract all IP addresses from files that start with “access.log” printing one IP address per line.

A

find . -type f -iname “access.log*” -exec grep -Eo “([0-9]{1,3}.){3}[0-9]{1,3}” {} \;

53
Q

How would you print the files in the current directory that have the text “John Williams” but NOT “John Williamson” in all text files?

A

grep -w “John Williams” *.txt

54
Q

How would you print the files in the current directory that have the text “John Williams” and “john williams”, but NOT “John Williamson” in all text files?

A

grep -wi “John Williams” *.txt

55
Q

How would you print the files in the current directory that have the text “John Williams” and “john williams”, but NOT “John Williamson” in all text files, and what line the text appears on?

A

grep -win “John Williams” *.txt

56
Q

How would you print the files in the current directory that have the text “John Williams” and “john williams”, but NOT “John Williamson” in all text files, and what line the text appears on, AND all the text that appears 4 lines before the searched text?

A

grep -win -B 4 “John Williams” *.txt

57
Q

How would you print the files in the current directory that have the text “John Williams” and “john williams”, but NOT “John Williamson” in all text files, and what line the text appears on, AND all the text that appears 4 lines after the searched text?

A

grep -win -A 4 “John Williams” *.txt

58
Q

How would you print the files in the current directory that have the text “John Williams” and “john williams”, but NOT “John Williamson” in all text files, and what line the text appears on, AND all the text that appears 4 lines BEFORE and AFTER the searched text?

A

grep -win -C 4 “John Williams” *.txt

59
Q

How would you print the files in the current directory that have the text “John Williams” and “john williams”, but NOT “John Williamson” in every file in the current directory, and what line the text appears on?

A

grep -win “John Williams” ./*

60
Q

How would you print the files in the current directory and all subdirectories (recursively) that have the text “John Williams” and “john williams”, but NOT “John Williamson” in all text files, and what line the text appears on, AND all the text that appears 4 lines BEFORE and AFTER the searched text?

A

grep -winr “John Williams” .

61
Q

How would you print the files in the current directory that have the text “John Williams” and “john williams”, but NOT “John Williamson” in all text files, and what line the text appears on, AND all the text that appears 4 lines BEFORE and AFTER the searched text?

Just print the path and file name and not the text in the file with a a match?

A

grep -wirl “John Williams” .

62
Q

How would you print the files in the current directory that have the text “John Williams” and “john williams”, but NOT “John Williamson” in all text files, and what line the text appears on, AND all the text that appears 4 lines BEFORE and AFTER the searched text?

Just print the path and file name and number of matches in each file, and not the text in the file with a a match?

A

grep -wirc “John Williams” .

63
Q

Delete all of the files in the current directory including all subdirectories and their contents?

A

find . -mindepth 1 -delete

64
Q

How do you count the number of files in the current working directory?

A

ls -l | wc -l

65
Q

Print all files in the current directory, one per line (not the path, just the filename) that contain the string “500”.

A

grep 500 -lhr

66
Q

Delete all of the files in this challenge directory including all subdirectories and their contents.

A

find . -delete

67
Q

Count the number of files in the current working directory. Print the number of files as a single integer.

A

ls -l | wc -l

68
Q

Print the number of lines in access.log that contain the string “GET”.

A

cat access.log | grep “GET” | wc -l

69
Q

The file split-me.txt contains a list of numbers separated by a ‘;’ character.
Split the numbers on the ‘;’ character, one number per line.

A

cat access.log | tr

70
Q

Print the numbers 1 to 100 separated by spaces.

A

echo {1..100}

71
Q

There are files in this challenge with different file extensions.
Remove all files with the .doc extension recursively in the current working directory.

A

find . -type f -name “*.doc” -delete

72
Q

The file sum-me.txt has a list of numbers, one per line. Print the sum of these numbers.

A

awk ‘BEGIN { sum=0 } { sum+=$1 } END { print sum }’ sum-me.txt

73
Q

Print all files in the current directory recursively without the leading directory path.

A

ls -R | grep [A-z]

74
Q

The file split-me.txt contains a list of numbers separated by a ‘;’ character.
Split the numbers on the ‘;’ character, one number per line.

A

tr “;” “\n”