Show Menu
Cheatography

Linux CLI Cheat Sheet (DRAFT) by [deleted]

Cheat Sheet for Linux CLI

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Notes

All commands are single line commands despite any line breaking.

Any commands containing "­$" are commands that accept one or more inputs. Examples of common inputs are as follows:

$file - A file such as "­/va­r/w­ww/­htm­l/i­nde­x.h­tml­"
$dir - A directory such as "­/va­r/w­ww/­htm­l/"
$pid - A process ID
$command - Another Linux command
$pattern - A RegEx pattern, or string such as "­htm­l" (string) or "­[\d­]{1­,2}­" (regex)
$domai­n.tld - A domain such as "­goo­gle.co­m"

System Inform­ation

cal
Show the calendar for the month
date
Show current date and time
uptime
Show current uptime
w
Show who is logged into the system
whoami
Show who you are logged in as
finger $user
Show inform­ation about $user
uname -a
Show kernel inform­ation
cat /proc/­cpuinfo
Show CPU inform­ation
cat /proc/­meminfo
Show memory inform­ation
man $command
Show the manual page for $command
df -h
Show disk usage
du -h
Show current directory space usage
free -m
Show memory usage in MB
which $command
Shows location of executable for $command
 

Search

grep $pattern $file
Search inside $file for $pattern
grep -r $pattern $dir
Search all files inside of $dir for $pattern
$command | grep $pattern
Search output of $command for $pattern
locate $file
Find all instances of $file

Process Management

ps aux
Show all running processes
top
Monitor all running processes
kill $pid
Kill process with pid $pid
kill -9 $pid
Force kill process with pid $pid
killall $proc
Kill all processes named $proc
bg
Lists stopped or background processes
fg
Bring the most recent process to the foreground
fg $a
Brings process $a to the foreground
ps aux and top both give you the pid of a process

Keyboard Shortcuts

CTRL-C
Halt the current process
CTRL-Z
Stop the current process (Resume with fg or resume in background with bg)
CTRL-D
Logout of session
CTRL-W
Erase from cursor to end of word
CTRL-U
Erase entire line
CTRL-A
Move cursor to start of line
CTRL-E
Move cursor to end of line
 

File and Directory Management

pwd
Print path of current directory
ls
List files and direct­ories in current directory
cd $dir
Change to directory at $dir
mkdir $dir
Make a directory called $dir
rm $file
Delete $file
rm -r $dir
Delete directory $dir
mv $a $b
Move file or directory at $a to $b. If $b is a directory, the file will be put inside of the directory. If $b is a file name, it will be overwr­itten with $a
With "rm $" and "rm -r" adding "­-f" will force the file or directory to be deleted regardless of the state of object.

Network

ping $host
Ping $host and output results
whois $domai­n.tld
Get registry inform­ation for $domai­n.tld
nslookup $domai­n.tld
Get abbrv. DNS inform­ation for $domai­n.tld
dig $domai­n.tld
Get full DNS inform­ation for $domai­n.tld
dig -x $domai­n.tld
Get reverse DNS inform­ation for $domai­n.tld
wget $url
Download file at $url

File Permis­sions

There are two ways to change file permis­sions:

chmod $octal $file
chmod $perms $file

Where $octal is a triad of octal digits (000 to 777)

Where 4 = read permis­sions, 2 = write permis­sions, 1 = execute permis­sions. You can define permis­sions by adding together the octals digits such that 5 = read/e­xecute permis­sions, 6 = read/w­rite, 3 = write/­exe­cute, and so on.

Each position represents permis­sions for "­own­er" "­gro­up" and "­wor­ld".