linux commands Flashcards
How do you connect to bandit.labs.overthewire.org on port 2220 with the username bandit0?
ssh bandit0@bandit.labs.overthewire.org -p 2220
Standard Unix/Linux command used to check the information of disk usage of files and directories on a machine?
du
What are two ways to read a file named ‘-‘ ?
- cat
How do you read a file that has spaces in the filename?
place the filename in single quotes
EX: cat ‘spaces in the filename’
How do you display hidden files in a directory?
ls -a
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”?
sshpass -p ‘cat bandit0’ ssh bandit0@bandit.labs.ovedrthewire.org -p 2220
How would you determine the types of files in a directory named “inhere” that all start with “-“?
file ./*
How would you read all the contents of every file within a directory named “inhere” that all start with “-“?
strings ./*
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
find ! -executable -size 1033c
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
find / -size 33c -user bandit7 -group bandit6 2>/dev/null
Search the file “data.txt” for the line with the word “millionth”.
cat data.txt | grep millionth
How do you search the file “data.txt” for the line of text that appears only once.
cat data.txt | sort | uniq -c
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’?
cat data.txt | sort | uniq -c | grep -v “10”
Search the file “data.txt” for the few human-readable strings that begin with several ‘=’ characters.
strings data.txt | grep “=”
What is the sign that something is Base64 encoded?
The string ends in 0, 1, 2, or 3 “=” sign
How do you decode the string of data within the file “data.txt” that is Base64 encoded?
cat data.txt | base64 -d
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?
cat data.txt
– displays the text “Gur cnffjbeq vf 5Gr8L4qetPEsPk8htqjhRK8XSP6x2RHh”–
echo “Gur cnffjbeq vf 5Gr8L4qetPEsPk8htqjhRK8XSP6x2RHh” | rot13
How do you take a hexdump file and reverse the hexdump process to a readable file?
xxd -reverse data.txt > newfile
How do you uncompress the file “data.gz”?
gunzip data.gz
How do you uncompress the file “data.bz2”?
bunzip2 data.bz2
How do you uncompress a file “data.txt” that is a POSIX tar archive file type?
tar xf data.txt
How do you ssh to ‘localhost’ with user bandit14 using the key “sshkey.private” located in the current directory?
ssh -i sshkey.private bandit14@localhost
How do you netcat a password that is in /etc/bandit_pass/bandit14 to port 30000 on localhost?
cat /etc/bandit_pass/bandit14 | nc localhost 30000
How to list all contents, including permissions, and hidden files of the current directory?
ls -la
How do you make a python file named file.py executable?
chmod +x file.py
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
How do you write text to a file?
echo Hello World > peanuts.txt
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»_space; peanuts.txt
What is the file descriptor for stdin, stdout, and stderr?
- stdin = 0
- stdout = 1
- stderr = 2