Bash Cheat Sheet
A cheat sheet for bash commands.
Command History
!! # Run the last command
touch foo.sh
chmod +x !$ # !$ is the last argument of the last command i.e. foo.shNavigating Directories
pwd # Print current directory path
ls # List directories
ls -a|--all # List directories including hidden
ls -l # List directories in long form
ls -l -h|--human-readable # List directories in long form with human readable sizes
ls -t # List directories by modification time, newest first
stat foo.txt # List size, created and modified timestamps for a file
stat foo # List size, created and modified timestamps for a directory
tree # List directory and file tree
tree -a # List directory and file tree including hidden
tree -d # List directory tree
cd foo # Go to foo sub-directory
cd # Go to home directory
cd ~ # Go to home directory
cd - # Go to last directory
pushd foo # Go to foo sub-directory and add previous directory to stack
popd # Go back to directory in stack saved by `pushd`Creating Directories
Moving Directories
Deleting Directories
Creating Files
Standard Output, Standard Error and Standard Input
Moving Files
Deleting Files
Reading Files
File Permissions
#
Permission
rwx
Binary
User
Group
Others
Description
Finding Files
Find in Files
Replace in Files
Symbolic Links
Compressing Files
zip
gzip
tar -c
Decompressing Files
unzip
gunzip
tar -x
Disk Usage
Memory Usage
Packages
Shutdown and Reboot
Identifying Processes
Process Priority
Killing Processes
Date & Time
Scheduled Tasks
HTTP Requests
Network Troubleshooting
DNS
Hardware
Terminal Multiplexers
Secure Shell Protocol (SSH)
Secure Copy
Bash Profile
Bash Script
Variables
Environment Variables
Functions
Exit Codes
Conditional Statements
Last updated