Linux Commands – Cheat Sheet

Sharing is caring

Views: 11

Bash Commands

uname -aShow system and kernel
head -n1 /etc/issueShow distri­bution
mountShow mounted filesy­stems
dateShow system date
uptimeShow uptime
whoamiShow your username
man commandShow manual for command

ls Options

-aShow all (including hidden)
-RRecursive list
-rReverse order
-tSort by last modified
-SSort by file size
-lLong listing format
-1One file per line
-mComma-­sep­arated output
-QQuoted output

Search Files

grep pattern filesSearch for pattern in files
grep -iCase insens­itive search
grep -rRecursive search
grep -vInverted search
grep -oShow matched part of file only
find /dir/ -name name*Find files starting with name in dir
find /dir/ -user nameFind files owned by name in dir
find /dir/ -mmin numFind files modifed less than num minutes ago in dir
whereis commandFind binary / source / manual for command
locate fileFind file (quick search of system index)

IO Redire­ction

cmd < fileInput of cmd from file
cmd1 <(cmd2)
Output of cmd2 as file input to cmd1
cmd > file
Standard output (stdout) of cmd to file
cmd > /dev/null
Discard stdout of cmd
cmd >> file
Append stdout to file
cmd 2> file
Error output (stderr) of cmd to file
cmd 1>&2
stdout to same place as stderr
cmd 2>&1
stderr to same place as stdout
cmd &> file
Every output of cmd to file

Nano Shortcuts

Files
Ctrl-RRead file
Ctrl-OSave file
Ctrl-XClose file
Cut and Paste
ALT-AStart marking text
CTRL-KCut marked text or line
CTRL-UPaste text
Navigate File
ALT-/End of file
CTRL-ABeginning of line
CTRL-EEnd of line
CTRL-CShow line number
CTRL-_Go to line number
Search File
CTRL-WFind
ALT-WFind next
CTRL-\Search and replace

Pipes

cmd1 | cmd2stdout of cmd1 to cmd2
cmd1 |& cmd2stderr of cmd1 to cmd2

Command Lists

cmd1 ; cmd2Run cmd1 then cmd2
cmd1 && cmd2Run cmd2 if cmd1 is successful
cmd1 || cmd2Run cmd2 if cmd1 is not successful
cmd &Run cmd in a subshell

Process Management

psShow snapshot of processes
topShow real time processes
kill pidKill process with id pid
pkill nameKill process with name name
killall nameKill all processes with names beginning name