Bash Shortcuts & Commands Cheat Sheet
Essential keyboard shortcuts and commands for working faster in the terminal. Bookmark this page for quick reference.
| Shortcut | Description |
Ctrl + A | Move cursor to the beginning of the line |
Ctrl + E | Move cursor to the end of the line |
Ctrl + F | Move cursor one character forward |
Ctrl + B | Move cursor one character backward |
Alt + F | Move cursor one word forward |
Alt + B | Move cursor one word backward |
Ctrl + XX | Toggle between current position and start of line |
| Shortcut | Description |
Ctrl + W | Delete the word before the cursor |
Alt + D | Delete the word after the cursor |
Ctrl + U | Delete from cursor to the beginning of the line |
Ctrl + K | Delete from cursor to the end of the line |
Ctrl + Y | Paste (yank) the last deleted text |
Ctrl + T | Swap the last two characters before the cursor |
Alt + T | Swap the last two words before the cursor |
Alt + U | Uppercase the word from cursor to end of word |
Alt + L | Lowercase the word from cursor to end of word |
Alt + C | Capitalize the character at cursor and move to end of word |
Ctrl + D | Delete the character under the cursor (or exit shell if line is empty) |
Ctrl + H | Delete the character before the cursor (same as Backspace) |
| Shortcut / Command | Description |
Ctrl + R | Reverse search through command history |
Ctrl + G | Cancel history search and restore original line |
Ctrl + P | Previous command in history (same as Up arrow) |
Ctrl + N | Next command in history (same as Down arrow) |
!! | Repeat the last command |
!$ | Last argument of the previous command |
!* | All arguments of the previous command |
!abc | Run the most recent command starting with "abc" |
!abc:p | Print (don't run) the most recent command starting with "abc" |
^old^new | Replace "old" with "new" in the previous command and run it |
history | Show full command history with line numbers |
history | grep <term> | Search command history for a specific term |
Alt + . | Insert the last argument of the previous command |
| Shortcut / Command | Description |
Ctrl + C | Kill the current foreground process (send SIGINT) |
Ctrl + Z | Suspend the current foreground process (send SIGTSTP) |
Ctrl + D | Send EOF — close the current shell or input stream |
bg | Resume a suspended process in the background |
fg | Bring a background process to the foreground |
fg %n | Bring job number n to the foreground |
jobs | List all background and suspended jobs |
command & | Run a command in the background |
kill %n | Kill job number n |
kill -9 <pid> | Force kill a process by PID (send SIGKILL) |
nohup command & | Run a command immune to hangups, even after logout |
| Command | Description |
ls -la | List all files including hidden, with details |
cp <src> <dest> | Copy a file from source to destination |
cp -r <dir> <dest> | Recursively copy a directory and its contents |
mv <src> <dest> | Move or rename a file or directory |
rm <file> | Remove a file |
rm -rf <dir> | Recursively force-remove a directory (use with caution) |
mkdir -p <path> | Create a directory and any missing parent directories |
find . -name "*.log" | Find files by name pattern in the current directory tree |
find . -type f -mtime -7 | Find files modified in the last 7 days |
chmod 755 <file> | Set file permissions (owner rwx, group rx, others rx) |
chown user:group <file> | Change file owner and group |
ln -s <target> <link> | Create a symbolic link |
| Command | Description |
grep "pattern" <file> | Search for a pattern in a file |
grep -r "pattern" <dir> | Recursively search for a pattern in all files |
grep -i "pattern" <file> | Case-insensitive search |
sed 's/old/new/g' <file> | Replace all occurrences of "old" with "new" |
sed -i 's/old/new/g' <file> | In-place replacement (modifies the file directly) |
awk '{print $1}' <file> | Print the first column of each line |
awk -F: '{print $1}' /etc/passwd | Print first field using colon as delimiter |
sort <file> | Sort lines alphabetically |
sort -n <file> | Sort lines numerically |
uniq | Remove adjacent duplicate lines (use after sort) |
wc -l <file> | Count lines in a file |
head -n 20 <file> | Show the first 20 lines of a file |
tail -n 20 <file> | Show the last 20 lines of a file |
tail -f <file> | Follow a file in real time (useful for logs) |
cut -d',' -f1,3 <file> | Extract fields 1 and 3 from a comma-delimited file |
tr 'a-z' 'A-Z' | Translate lowercase to uppercase |
| Operator / Command | Description |
command > file | Redirect stdout to a file (overwrite) |
command >> file | Redirect stdout to a file (append) |
command < file | Use file as stdin for the command |
command 2> file | Redirect stderr to a file |
command 2>&1 | Redirect stderr to stdout |
command &> file | Redirect both stdout and stderr to a file |
cmd1 | cmd2 | Pipe stdout of cmd1 to stdin of cmd2 |
cmd1 |& cmd2 | Pipe both stdout and stderr of cmd1 to cmd2 |
command | tee file | Write output to both stdout and a file |
command | tee -a file | Append output to both stdout and a file |
command | xargs cmd | Pass output lines as arguments to another command |
command | xargs -I{} cmd {} | Use each input line as a placeholder in the command |
| Command | Description |
sudo !! | Re-run the last command with sudo |
cd - | Switch to the previous working directory |
mkdir -p dir && cd $_ | Create a directory and cd into it |
du -sh * | Show disk usage of each item in the current directory |
df -h | Show disk space usage in human-readable format |
watch -n 5 command | Run a command every 5 seconds and display output |
alias ll='ls -la' | Create a shortcut alias for a command |
tar czf archive.tar.gz dir/ | Create a gzipped tar archive of a directory |
tar xzf archive.tar.gz | Extract a gzipped tar archive |
curl -O <url> | Download a file from a URL |
diff <(cmd1) <(cmd2) | Compare the output of two commands |
column -t <file> | Format output into aligned columns |
yes | command | Automatically answer "yes" to all prompts |
Ctrl + L | Clear the terminal screen (same as the clear command) |