Linux Command Line Cheat Sheet by Dave Child (DaveChild) via cheatography.com/1/cs/49/
Bash Commands Bash Variables (cont) Command Lists uname -a Show system and kernel export NAME=value Set $NAME to value cmd1 ; cmd2 head -n1 /etc/issue Show distrib ution $PATH Executable search path Run cmd1 then cmd2 mount Show mounted $HOME Home directory cmd1 && cmd2 filesys tems $SHELL Current shell Run cmd2 if cmd1 is successful date Show system date cmd1 || cmd2 uptime Show uptime IO Redirec tion Run cmd2 if cmd1 is not successful whoami Show your username cmd < file cmd & man command Show manual for Input of cmd from file command Run cmd in a subshell cmd1 <(cmd2)
Output of cmd2 as file input to cmd1 Bash Shortcuts Directory Operations cmd > file CTRL-c Stop current command pwd Show current directory Standard output (stdout) of cmd to file CTRL-z Sleep program mkdir dir Make directory dir
CTRL-a Go to start of line cmd > /dev/null cd dir Change directory to dir
CTRL-e Go to end of line Discard stdout of cmd cd .. Go up a directory
CTRL-u Cut from start of line cmd >> file ls List files
CTRL-k Cut to end of line Append stdout to file ls Options CTRL-r Search history cmd 2> file -a Show all (including hidden) !! Repeat last command Error output (stderr) of cmd to file -R Recursive list !abc Run last command starting with cmd 1>&2 abc -r Reverse order stdout to same place as stderr !abc:p Print last command starting with -t Sort by last modified cmd 2>&1 abc -S Sort by file size stderr to same place as stdout !$ Last argument of previous -l Long listing format command cmd &> file -1 One file per line ALT-. Last argument of previous Every output of cmd to file -m Comma-s epa rated output command cmd refers to a command. -Q Quoted output !* All arguments of previous command Pipes Search Files ^abc^123 Run previous command, replacing abc with 123 cmd1 | cmd2 grep pattern files Search for pattern in stdout of cmd1 to cmd2 files Bash Variables grep -i Case insensi tive cmd1 |& cmd2 search env Show environ ment variables stderr of cmd1 to cmd2 grep -r Recursive search echo $NAME Output value of $NAME variable grep -v Inverted search grep -o Show matched part of file only
find /dir/ -name name* Find files starting with name in dir
By Dave Child (DaveChild) Published 28th October, 2011. Sponsored by Readability-Score.com cheatography.com/davechild/ Last updated 28th March, 2016. Measure your website readability! www.getpostcookie.com Page 1 of 2. https://readability-score.com Linux Command Line Cheat Sheet by Dave Child (DaveChild) via cheatography.com/1/cs/49/
Search Files (cont) Process Management Screen Shortcuts (cont) find /dir/ -user name Find files owned by ps Show snapshot of processes screen -list
name in dir top Show real time processes Show your current screen sessions. find /dir/ -mmin num Find files modifed less kill pid Kill process with id pid CTRL-A than num minutes ago in pkill name Kill process with name name dir Activate commands for screen. killall name Kill all processes with names whereis command Find binary / source / CTRL-A c beginning name manual for command Create a new instance of terminal. locate file Find file (quick search of Nano Shortcuts CTRL-A n system index) Go to the next instance of terminal. Files
File Operations Ctrl-R Read file CTRL-A p touch file1 Ctrl-O Save file Go to the previous instance of terminal.
Create file1 Ctrl-X Close file CTRL-A " cat file1 file2 Cut and Paste Show current instances of terminals.
Concate nate files and output ALT-A Start marking text CTRL-A A less file1 CTRL-K Cut marked text or line Rename the current instance.
View and paginate file1 CTRL-U Paste text More screen info at: Navigate File http:// www .gn u.or g/ sof twa re/ scr een/ file file1
ALT-/ End of file Get type of file1 File Permiss ions CTRL-A Beginning of line cp file1 file2 chmod 775 file CTRL-E End of line Copy file1 to file2 CTRL-C Show line number Change mode of file to 775 mv file1 file2 CTRL-_ Go to line number chmod -R 600 folder Move file1 to file2 Search File Recursi vely chmod folder to 600 rm file1 CTRL-W Find chown user:group file Delete file1 ALT-W Find next Change file owner to user and group to head file1 group CTRL-\ Search and replace Show first 10 lines of file1 More nano info at: File Permission Numbers tail file1 http:// www .na no- edi tor .or g/d ocs .php Show last 10 lines of file1 First digit is owner permiss ion, second is group Screen Shortcuts and third is everyone. tail -F file1 Calculate permission digits by adding numbers Output last lines of file1 as it changes screen below. Start a screen session. 4 read (r) Watch a Command screen -r 2 write (w) watch -n 5 'ntpq -p' Resume a screen session. 1 execute (x) Issue the 'ntpq -p' command every 5 seconds and display output
By Dave Child (DaveChild) Published 28th October, 2011. Sponsored by Readability-Score.com cheatography.com/davechild/ Last updated 28th March, 2016. Measure your website readability! www.getpostcookie.com Page 2 of 2. https://readability-score.com