Unix Command Cheatsheet
2 November 2015
cd
change directorycd <directory>
changes to directorycd ..
parent directorycd ../..
two directories up~
alias to home directorytouch
updates or changes file modification time. Creates file if it doesn’t exist.touch -c <file>
prevents creation of file only updatesls
lists contents of the current directoryls -la
shows hidden files tools -1
prints list of files in folder each on its own linepwd
show the current (working) directory’s pathcp
copycp -r
recursive copyscp
secure copymv <file1> <file2>
copies file contents from one file to another (essentially changes the name of the file)mv <dir1> <dir2>
copies directory contents from one directory to another (essentially changes the name of the directory)mkdir <dirname>
creates a directory named<dirname>
mkdir -p
creates any directory that doesn’t exist (good for creating nested directories as inmkdir foo/bar/baz
)cat
output file contents (as many files as you like separated by space)stat <file>
statistics about file (permissions, time created, time modified)wc
word count-l
lines-w
words-c
charactershead -n5 <file>
first 5 (or n) lines of a filetail -n5 <file>
last 5 (or n) lines of a filetail -f <file>
updates the end of a file when more input is added. (Good for log files)gzip
a compression programgunzip
a decompression programfind
search for filesmysql
connect to a MySQL servermysqldump
“dump” from a MySQL server|
“pipe” output to another program (standard output of one programme to standard input of another one)>
output to a file>>
append to the end of a file<
input from a filegrep <regex>
find using regular expression (-E
to avoid having to escape metacharacters)sed s/<regex>/<replace>/g
search-replace using regular expression (-r
or-E
to avoid having to escape metacharacters)perldoc perlreref
handy regex reference probably already on systemrm
remove / delete (be careful on this one)<command> --help
many programs have a built-in “help” to show you basic usage informationman <command>
“manual” program to show information on how to use a commandchmod 755 <file>
gives full permissions to a file (not always a good idea so make sure you know what you’re doing)host myip.opendns.com resolver1.opendns.com
- returns your current IP addressnano ~/.bash_profile
to edit the .bash_profile (with nano)source ~/.bash_profile
to save changesreset
resets terminal (hit enter even if you can’t see the command)echo
prints to screen (good for testing output of previous commands especially when using wild-cards or brace expansion)cal 2015
calendar of 2015cal -3
previous current and next month’s calendar
This is a conglomeration of several online cheatsheets, the origins of which are noted in the resources section below are completely forgotten. It also includes my own notes. Please feel free to inform me of any wrong information or to any which are vital but may have been overlooked.
For more specific use cases see Unix Cheatsheet 2