Bash-Cheat-Sheet
README.md
Bash Cheat Sheet
A cheat sheet for bash commands.
Command History
Navigating Directories
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 |
|---|---|---|---|
| 7 | read, write and execute | rwx | 111 |
| 6 | read and write | rw- | 110 |
| 5 | read and execute | r-x | 101 |
| 4 | read only | r-- | 100 |
| 3 | write and execute | -wx | 011 |
| 2 | write only | -w- | 010 |
| 1 | execute only | --x | 001 |
| 0 | none | --- | 000 |
For a directory, execute means you can enter a directory.
| User | Group | Others | Description |
|---|---|---|---|
| 6 | 4 | 4 | User can read and write, everyone else can read (Default file permissions) |
| 7 | 5 | 5 | User can read, write and execute, everyone else can read and execute (Default directory permissions) |
- u - User
- g - Group
- o - Others
- a - All of the above
Finding Files
Find binary files for a command.
uses an index and is fast.locate
doesn't use an index and is slow.find
Find in Files
Replace in Files
Symbolic Links
Compressing Files
zip
Compresses one or more files into *.zip files.
gzip
Compresses a single file into *.gz files.
tar -c
Compresses (optionally) and combines one or more files into a single *.tar, *.tar.gz, *.tpz or *.tgz file.
Decompressing Files
unzip
gunzip
tar -x
Disk Usage
Memory Usage
Packages
Shutdown and Reboot
Identifying Processes
Process Priority
Process priorities go from -20 (highest) to 19 (lowest).
Killing Processes
Date & Time
Scheduled Tasks
HTTP Requests
Network Troubleshooting
DNS
Hardware
Terminal Multiplexers
Start multiple terminal sessions. Active sessions persist reboots. is more modern than tmux.screen
Secure Shell Protocol (SSH)
Set default user and port in , so you can just enter the name next time:~/.ssh/config
Secure Copy
Bash Profile
- bash - .bashrc
- zsh - .zshrc
Bash Script
Variables
Environment Variables
Functions
Exit Codes
Conditional Statements
Boolean Operators
- Is true$foo- Is false!$foo
Numeric Operators
- Equals-eq- Not equals-ne- Greater than-gt- Greater than or equal to-ge- Less than-lt- Less than or equal to-lefoo.txt - Check file exists-efoo - Check if variable exists-z
String Operators
- Equals=- Equals==- Is null-z- Is not null-n- Is less than in ASCII alphabetical order<- Is greater than in ASCII alphabetical order>