| Command | Purpose | Options to know | Examples |
|---|---|---|---|
| echo | Repeats back whatever you tell it | echo ~ echo “This is a string of text” | |
| cat | Reads the contents of a file and prints it out to the terminal | ||
| head | Reads a certain number of lines from the top or start of the file | You can specify the number of lines to read with -X, for example -2 or -54. -n X also works. | head -20 head -n 20 head -35 |
| tail | Reads a certain number of lines from the bottom or end of a file | All head options You can tell tail to “follow” or keep reading from the end of a file with -f | tail -20 tail -n 20 tail -f apachelogfile.txt |
| grep | Searches through text for a given string of characters | You can either send text to grep with | or point it at a text file by giving it a filename as its second argument. If your search string has spaces in it, quote it or grep will assume you’re giving it a list of filenames. | cat file.txt | grep “my password is” echo “This is a string of text | grep “text grep “my password is” file.txt |
| cut | Splits each line of text into columns based on a given delimiter (space, comma, semicolon, tab, period, etc.) and selects a column or columns to show | -d to specify a delimiter -f to specify the column or columns to show | cat apache.log | cut -d “ “ -f 10 cat apache.log | cut -d : -f 3-8 |
| sort | Sorts lines of text in alphabetical order | -n to sort according to numerical value instead of alphabetical order | |
| uniq | Removes duplicate lines in the text you feed it | -c to keep count of how many duplicate lines it removes instead of just silently removing. You have to sort text before feeding it to uniq. | |
| wc | Counts the number of words in the text you give it | -l to count lines of text instead of words. | cat apache.log | grep “Authentication Failure” | wc -l |
| more/less | Shows output one page at a time, allows you to scroll up and down with arrow keys | Press q to exit. | cat log.txt | less less log.txt |
| nano | Interactive text editor | Ctrl+o to “write out” or save a file Ctrl+x to exit | nano nano magnumopus.txt |
| pwd | Print Working Directory (tells you the full path to the folder you’re in) | ||
| cd | Change Directory | cd workfolder cd ~ cd /etc/ssh | |
| rm | Removes files and folders | -r to remove recursively, deleting folders as well as files | |
| mkdir | Makes a folder | ||
| rmdir | Deletes an empty folder | ||
| find | Looks for files by listing each folder and looking inside | -name to specify a filename | find / -name *.log find /home/student -name Homework.docx |
| locate | Looks for files based on a local database of filenames that’s updated every 24 hours. | locate *.log locate Homework.docx | |
| touch | Creates an empty file or updates the “last modified” timestamp on an existing file | ||
| file | Reads the first few bytes of a file and makes an educated guess about what file format it is | ||
| strings | Looks through a binary file for any text that looks human-readable | strings ctfmemorydump.bin | |
| ls | Lists the folders and files in the current directory or a target directory | -a to show hidden files -l for the long version of file info including file permissions -H to convert bytes into human-readable sizes like KB, MB, GB | |
| tree | Shows folders and files in a tree structure | ||
| chmod | Changes the “mode” (permissions) of a file | chmod 777 file.txt chmod u=rwx file.txt | |
| chown | Changes the owner of a file | -R to recursively change permissions on a folder and every file/folder under it | chown student file.txt chown -R student /home/student |
| chgrp | Changes the group that owns a file | ||
| whoami | Tells you the username you’re logged in as | ||
| groups | Lists the groups you’re a member of | ||
| free | Shows the amount of memory used and available | -h to show human-readable sizes like KB, MB, GB instead of showing just bytes | free -h |
| df | Stands for Disk Free, shows the amount of storage used and available | Again, -h to show human-readable sizes | df -h df -h / df -h /tmp |
| tar | Combines multiple files into a single file and vice versa. Short for Tape Archive. | Compression and archiving | |