Linux Command Line Cheat Sheet
by Dave Child (DaveChild) via [Link]/1/cs/49/
Bash Commands
uname -a head -n1 /etc/issue mount date uptime whoami man command Show system and kernel Show distribution Show mounted lesystems Show system date Show uptime Show your username Show manual for
command
Bash Variables
env echo $NAME export
NAME =value
Command Lists
Show environment variables Output value of $NAME variable Set $NAME to value Executable search path Home directory Current shell
cmd1 ; cmd2
$PATH $HOME $SHELL
Run cmd1 then cmd2 cmd1 && cmd2 Run cmd2 if cmd1 is successful cmd1 || cmd2 Run cmd2 if cmd1 is not successful cmd & Run cmd in a subshell
IO Redirection
< le Input of cmd from le cmd1 <(cmd2 ) Output of cmd2 as le input to cmd1 cmd > le Standard output (stdout) of cmd to
cmd le
Directory Operations
pwd mkdir dir cd dir cd .. ls Show current directory Make directory dir Change directory to dir Go up a directory List les
Bash Shortcuts
CTRL-c CTRL-z CTRL-a CTRL-e CTRL-u CTRL-k CTRL-r !! !abc Stop current command Sleep program Go to start of line Go to end of line Cut from start of line Cut to end of line Search history Repeat last command Run last command starting with abc !abc :p Print last command starting with abc !$ Last argument of previous command ALT-. Last argument of previous command !* All arguments of previous command \^abc \^123 Run previous command, replacing abc with 123
ls Options
-a -R -r -t -S -l -1 -m -Q Show all (including hidden) Recursive list Reverse order Sort by last modied Sort by le size Long listing format One le per line Comma-separated output Quoted output
> /dev/null Discard stdout of cmd cmd le Append stdout to le cmd 2> le Error output (stderr) of cmd to le cmd 1>&2 stdout to same place as stderr cmd 2>&1 stderr to same place as stdout cmd &> le Every output of cmd to le cmd refers to a command.
cmd
Pipes
cmd1 | cmd2
stdout of cmd1 to cmd2 cmd1 |& cmd2 stderr of cmd1 to cmd2
Cheatographer
Dave Child (DaveChild) [Link]/davechild [Link]
Cheat Sheet
Published 28th October, 2011. Updated 12th May, 2013. Page 1 of 3.
Sponsor
Measure your website readability! [Link]
Linux Command Line Cheat Sheet
by Dave Child (DaveChild) via [Link]/1/cs/49/
Search Files
grep pattern
les
File Operations
Search for pattern in
les
grep -i grep -r grep -v grep -o nd /dir/ -name name * nd /dir/ -user
name
nd /dir/ -mmin num whereis
command
locate le
Case insensitive search Recursive search Inverted search Show matched part of le only Find les starting with name in dir Find les owned by name in dir Find les modifed less than num minutes ago in dir Find binary / source / manual for command Find le (quick search of system index)
touch le1 Create le1 cat le1 le2 Concatenate les and output less le1 View and paginate le1 le le1 Get type of le1 cp le1 le2 Copy le1 to le2 mv le1 le2 Move le1 to le2 rm le1 Delete le1 head le1 Show rst 10 lines of le1 tail le1 Show last 10 lines of le1 tail -f le1 Output last lines of le1 as it changes
Nano Shortcuts Files
Ctrl-R Ctrl-O Ctrl-X Read le Save le Close le Start marking text Cut marked text or line Paste text End of le Beginning of line End of line Show line number Go to line number
Cut and Paste
ALT-A CTRLK CTRLU
Navigate File
ALT-/ CTRLA CTRL-E CTRL-C CTRL_
Search File
CTRL- Find W ALT-W Find next CTRL-\ Search and replace More nano info at: [Link]
Process Management
ps top kill pid pkill name killall
name
Show snapshot of processes Show real time processes Kill process with id pid Kill process with name name Kill all processes with names beginning name
Watch a Command
watch -n 5 'ntpq -p' Issue the 'ntpq -p' command every 5 seconds and display output
Cheatographer
Dave Child (DaveChild) [Link]/davechild [Link]
Cheat Sheet
Published 28th October, 2011. Updated 12th May, 2013. Page 2 of 3.
Sponsor
Measure your website readability! [Link]
Linux Command Line Cheat Sheet
by Dave Child (DaveChild) via [Link]/1/cs/49/
Screen Shortcuts
screen Start a screen session. screen -r Resume a screen session. screen -list Show your current screen sessions. CTRL-A Activate commands for screen. CTRL-A c Create a new instance of terminal. CTRL-A n Go to the next instance of terminal. CTRL-A p Go to the previous instance of terminal. CTRL-A " Show current instances of terminals. CTRL-A A Rename the current instance. More screen info at: [Link]
File Permissions
chmod 775 le Change mode of le to 775 chmod -R 600 folder Recursively chmod folder to 600 chown user :group le Change le owner to user and group to group
File Permission Numbers
The rst digit is the owner permission, the second the group and the third for everyone. Calculate each of the three permission digits by adding the numeric values of the permissions below. 4 read (r) 2 write (w) 1 execute (x)
Cheatographer
Dave Child (DaveChild) [Link]/davechild [Link]
Cheat Sheet
Published 28th October, 2011. Updated 12th May, 2013. Page 3 of 3.
Sponsor
Measure your website readability! [Link]