You are on page 1of 2

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 distri​bution $PATH Executable search path Run cmd1 then cmd2

mount Show mounted $HOME Home directory cmd1 && cmd2


filesy​stems
$SHELL Current shell Run cmd2 if cmd1 is successful
date Show system date
cmd1 || cmd2
uptime Show uptime IO Redire​ction
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)

Bash Shortcuts Output of cmd2 as file input to cmd1 Directory Operations

cmd > file pwd Show current directory


CTRL-c Stop current command
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
!! Repeat last command -a Show all (including hidden)
Error output (stderr) of cmd to file
!abc Run last command starting with -R Recursive list
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
abc cmd 2>&1
-S Sort by file size
!$ Last argument of previous stderr to same place as stdout
-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-​sep​arated 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 insens​itive
cmd1 |& cmd2
search
env Show enviro​nment 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 13th May, 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 Activate commands for screen.
dir
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.

Concat​enate 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:/​/ww​w.g​nu.o​rg​/so​ftw​are​/sc​reen/
file file1
ALT-/ End of file
Get type of file1
File Permis​sions
CTRL-A Beginning of line
cp file1 file2
CTRL-E End of line chmod 775 file
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 Recurs​ively 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:/​/ww​w.n​ano​-ed​ito​r.o​rg/​doc​s.php
Show last 10 lines of file1 First digit is owner permis​sion, 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 13th May, 2016. Measure your website readability!
www.getpostcookie.com Page 2 of 2. https://readability-score.com

You might also like