linux commands Flashcards

(74 cards)

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
How do you make a python file named file.py executable?
chmod +x file.py
26
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?
alias foobar='ls -la' make ~/.bashrc to make it persist after reboot
27
How do you write text to a file?
echo Hello World > peanuts.txt
28
How do you write text to a file, without deleting any existing text (append new text to the end of the existing file)?
echo Hello World >> peanuts.txt
29
What is the file descriptor for stdin, stdout, and stderr?
- stdin = 0 - stdout = 1 - stderr = 2
30
How would you redirect the standard error of "ls /fake/directory" to a special file that will discard any input?
ls /fake/directory 2> /dev/null
31
What does the pipe operator "|" do?
allows us to get the stdout of a command and make that the stdin to another process.
32
How would you write the output of "ls -la /etc" to a file and to the screen?
ls -la /etc | tee file.txt
33
How do you display the first 10 lines of file.txt?
head file.txt
34
How do you see the last ten lines of file.txt?
tail file.txt
35
How do you get the unique values of a file?
uniq -u file.txt
36
How would get the number of times a line appears in a file?
uniq -c file.txt
37
How would you get lines that are duplicated in a file?
uniq -d file.txt
38
What information about a file does "wc" provide?
- number of lines - number of words - number of bytes
39
How would you fine all of the instances of the word "Hello" in file.txt?
grep Hello file.txt
40
How would you list all of the files in the /etc directory with ".conf" extension?
ls /etc | grep .conf
41
How would you print all of the lines of file.txt that begin with "Hello"?
grep ^Hello file.txt
42
How would you print all of the lines that end with "seahorse"?
grep seahorse$ file.txt
43
How would you print all of the lines that start with the letter "H" in file.txt?
grep H. file.txt
44
How would you print all of the lines that start with either "dig", "dug", or "dog" in file.txt?
grep d[iou]g file.txt
45
How would you print the lines that start with "dog" and "dug", but not "dig"?
grep d[^i]g file.txt
46
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?
- /Hello - press 'n' to advance forward - press 'N' to go backwards
47
Print the relative file paths, one path per line for all filenames that start with "access.log" in the current directory.
ls acc*
48
How would you find all files in the current directory and all subdirectories that are of the type "file"?
ls . -type f
49
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?
find -name "access*" -exec grep -h '500' { } \;
50
Extract all IP addresses from files (recursively, all subdirectories) that start with "access.log" printing one IP address per line.
find . -type f -name "access.log*" -exec grep -oE
51
Regex for IP address?
([0-9]{1,3}\.)[0-9]{1,3}
52
Extract all IP addresses from files that start with "access.log" printing one IP address per line.
find . -type f -iname "access.log*" -exec grep -Eo "([0-9]{1,3}\.){3}[0-9]{1,3}" {} \;
53
How would you print the files in the current directory that have the text "John Williams" but NOT "John Williamson" in all text files?
grep -w "John Williams" *.txt
54
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?
grep -wi "John Williams" *.txt
55
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?
grep -win "John Williams" *.txt
56
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?
grep -win -B 4 "John Williams" *.txt
57
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?
grep -win -A 4 "John Williams" *.txt
58
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?
grep -win -C 4 "John Williams" *.txt
59
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?
grep -win "John Williams" ./*
60
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?
grep -winr "John Williams" .
61
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?
grep -wirl "John Williams" .
62
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?
grep -wirc "John Williams" .
63
Delete all of the files in the current directory including all subdirectories and their contents?
find . -mindepth 1 -delete
64
How do you count the number of files in the current working directory?
ls -l | wc -l
65
Print all files in the current directory, one per line (not the path, just the filename) that contain the string "500".
grep 500 -lhr
66
Delete all of the files in this challenge directory including all subdirectories and their contents.
find . -delete
67
Count the number of files in the current working directory. Print the number of files as a single integer.
ls -l | wc -l
68
Print the number of lines in access.log that contain the string "GET".
cat access.log | grep "GET" | wc -l
69
The file split-me.txt contains a list of numbers separated by a ';' character. Split the numbers on the ';' character, one number per line.
cat access.log | tr
70
Print the numbers 1 to 100 separated by spaces.
echo {1..100}
71
There are files in this challenge with different file extensions. Remove all files with the .doc extension recursively in the current working directory.
find . -type f -name "*.doc" -delete
72
The file sum-me.txt has a list of numbers, one per line. Print the sum of these numbers.
awk 'BEGIN { sum=0 } { sum+=$1 } END { print sum }' sum-me.txt
73
Print all files in the current directory recursively without the leading directory path.
ls -R | grep [A-z]
74
The file split-me.txt contains a list of numbers separated by a ';' character. Split the numbers on the ';' character, one number per line.
tr ";" "\n"