Unix Command Cheatsheet
2 November 2015
cdchange directorycd <directory>changes to directorycd ..parent directorycd ../..two directories up~alias to home directorytouchupdates or changes file modification time. Creates file if it doesn’t exist.touch -c <file>prevents creation of file only updateslslists contents of the current directoryls -lashows hidden files tools -1prints list of files in folder each on its own linepwdshow the current (working) directory’s pathcpcopycp -rrecursive copyscpsecure 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 -pcreates any directory that doesn’t exist (good for creating nested directories as inmkdir foo/bar/baz)catoutput file contents (as many files as you like separated by space)stat <file>statistics about file (permissions, time created, time modified)wcword count-llines-wwords-ccharactershead -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)gzipa compression programgunzipa decompression programfindsearch for filesmysqlconnect 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 (-Eto avoid having to escape metacharacters)sed s/<regex>/<replace>/gsearch-replace using regular expression (-ror-Eto avoid having to escape metacharacters)perldoc perlrerefhandy regex reference probably already on systemrmremove / delete (be careful on this one)<command> --helpmany 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_profileto edit the .bash_profile (with nano)source ~/.bash_profileto save changesresetresets terminal (hit enter even if you can’t see the command)echoprints to screen (good for testing output of previous commands especially when using wild-cards or brace expansion)cal 2015calendar of 2015cal -3previous 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