Cheatography
https://cheatography.com
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 "/var/www/html/index.html"
$dir - A directory such as "/var/www/html/"
$pid - A process ID
$command - Another Linux command
$pattern - A RegEx pattern, or string such as "html" (string) or "[\d]{1,2}" (regex)
$domain.tld - A domain such as "google.com" |
System Information
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 information about $user |
uname -a |
Show kernel information |
cat /proc/cpuinfo |
Show CPU information |
cat /proc/meminfo |
Show memory information |
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 directories 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 overwritten 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 $domain.tld |
Get registry information for $domain.tld |
nslookup $domain.tld |
Get abbrv. DNS information for $domain.tld |
dig $domain.tld |
Get full DNS information for $domain.tld |
dig -x $domain.tld |
Get reverse DNS information for $domain.tld |
wget $url |
Download file at $url |
File Permissions
There are two ways to change file permissions:
chmod $octal $file
chmod $perms $file
Where $octal is a triad of octal digits (000 to 777)
Where 4 = read permissions, 2 = write permissions, 1 = execute permissions. You can define permissions by adding together the octals digits such that 5 = read/execute permissions, 6 = read/write, 3 = write/execute, and so on.
Each position represents permissions for "owner" "group" and "world". |
|