Show Menu
Cheatography

de.NBI Workshops - Linux Bash at a Glance Cheat Sheet by

General Advice

Use the tab-co­mpl­etion:
Tab
and
double Tab

Use the history: and and
crtl+r

CMD = any command
TXT = any text; escape special chars with \ or " " or ' '
FILE = any file name including the path (full/­rel­ative) to this file
PATH = a FILE or a directory accord­ingly
[] = an argument to a CMD which is optional

Get Help

whatis CMD
display one-line descri­ptions of CMD
CMD -h (or -?,
-help, --help, --usage)
displays the help message of CMD
man CMD
displays the manual pages of CMD
info CMD
displays the info documents of CMD
help CMD
display inform­ation about the builtin CMD
apropos TEXT
search the man pages for TEXT
groups USER
shows all groups of USER (default is own)

Show File Content

head FILE
print the first 10 lines of each FILE
head -n X FILE
print the first X lines
tail FILE
print the last 10 lines of each FILE
tail -n X FILE
print the last X
less FILE
display FILE on a page-b­y-page basis
| less
display STDIN on a page-b­y-page basis
cat FILE
prints whole FILE
cat FILE1 FILE2 > FILE3
cats FILE1 and FILE2 and prints them to FILE3

Rediretcs & Pipes & Subshell

CMD > FILE
prints standard output of CMD to FILE, replacing it
CMD >> FILE
prints standard output of CMD to FILE, appending it
CMD1 | CMD2
'pipes' standard out of CMD1 as standard input to CMD2
CMD > out.log 2> err.log &
runs CMD in backgr­ound, prints standard out to out.log and standard error to err.log

Searching

grep TXT FILES
search for pattern TXT in FILES (line-­wise)
grep -r TXT PATH
searches all files in PATH recurs­ively
grep -v TXT PATH
show lines not containing TXT
grep -c TXT PATH
count matching lines instead of showing them
find [PATH] -name "TXT"
finds all files named TXT in PATH (default .)
find [PATH] -iname "*TXT*"
finds all files matching TXT case insens­itive

Operate On Filesystem

pwd
prints current directory
ls [PATH]
list directory contents
ls -lart [PATH]
long + hidden + reverse order + sort last modified
cd
changes to HOME directory
cd PATH
changes to PATH directory
mkdir PATH
creates a directory
mkdir -p PATH
creates also parents as needed
cp FILE PATH
copies FILE to PATH
cp -r PATH1 PATH2
cp recurs­ively whole directory PATH1 to PATH2
mv PATH1 PATH2
moves file or dir PATH1 to PATH2
rm FILE
removes FILE
rm -r PATH
removes files and dirs under PATH recurs­ively
ln -s PATH1
creates link of PATH with same name
ln -s PATH1 TXT
creates link of PATH with new name TXT
 

Helpers

alias TXT='CMD'
abbreviate CMD with TXT
alias ..='cd ..'
alias l='ls -lah'
CMD | wc -l
prints number of lines CMD generates as output
CMD | sort
sorts output of CMD alphab­etical
CMD | sort -n -k 3
sorts output of CMD numerical based on 3rd column
CMD | uniq
only prints unique lines of CMD output

Archives & Compre­ssion

gunzip FILE.gz
uncomp­resses the FILE.gz in-place
unzip FILE.zip
uncompress and extracts the ZIP archive FILE.zip
tar -xvzf FILE.tgz
extracts + uncompress (gzip) the tarball FILE.tgz
tar -xvf FILE.tar
extracts the tarball FILE.tar
tar -cvzf FILE.tgz PATH
archives and compresses PATH into FILE.tgz

Permis­sions

chmod OCTAL FILE
change the permis­sions of FILE (or directory) to OCTAL seperately for user, group and world by summing:
4 - read (r)
2 - write (w)
1 - execute (x)
Example: chmod 750 == rwx for owner, rx for group, none for world

Process Control

top
displays realtime inform­ation about the top cpu processes
ps
report snapshot of processes (in current shell)
ps -lfu USER
show all processes of USER in details
kill PID
terminate the process with the process ID PID

Shortcuts

Ctrl + c
Interr­upt­/Kill whatever you are running (SIGINT)
Ctrl + z
Suspends current task (SIGTSTP).
 
fg + Enter
: resume process
 
bg + Enter
: continue process in background
Shift + PageUp
Scroll terminal window up
Shift + PageDown
Scroll terminal window down

Shortcuts (cursor movement)

Ctrl + a
/
Home
Go to beginning of the line
Ctrl + e
/
End
Go to the End of the line
Ctrl + f
/
Forward one character
Ctrl + b
/
Backward one character
Ctrl + a
Delete current character
Backspace
Delete previous character
Shift + Insert
Paste text

Wildcards

*
replaces arbitrary number of characters
?
replaces exactly one character
[abc]
replaces exactly for a, b or c
[a-z]
replaces for any char from a to z

Navigation (less, man, ...)

h
display help message
q
quit
space-bar |
PageDown
one page down
b|
PageUp
one page up
q
quit
/ TXT
search forward for TXT
? TXT
search backward for TXT
n
repeat previous search
N
repeat previous search in reverse direction
G
Go to last line
g
Go to first line
           
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Administración de sistemas Cheat Sheet
          Linux Every Day Commands Cheat Sheet