Small efficiency gains add up to hours saved over time. These five terminal shortcuts and techniques are used daily by experienced Linux administrators and developers. Learn them once and benefit forever.
1. Reverse History Search (Ctrl+R)
Stop retyping long commands. Press Ctrl+R and start typing any part of a previous command:
# Press Ctrl+R, then type "docker"
(reverse-i-search)`docker': docker compose -f production.yml up -d
# Press Ctrl+R again to cycle through older matches
# Press Enter to execute, or Ctrl+C to cancel
# Press Right arrow to edit the command before executing
2. Command Substitution and Chaining
# Run command only if previous succeeds (&&)
sudo apt update && sudo apt upgrade -y
# Run command regardless of previous result (;)
make clean; make build; make test
# Run command only if previous fails (||)
ping -c 1 server.com || echo "Server is down!"
# Use output of one command in another
vim $(find . -name "config.yml")
kill $(pgrep -f "python app.py")
3. Powerful Aliases and Functions
Add these to your ~/.bashrc or ~/.zshrc:
# Quick navigation
alias ..="cd .."
alias ...="cd ../.."
alias ll="ls -alFh"
alias la="ls -A"
# Safety nets
alias rm="rm -i"
alias cp="cp -i"
alias mv="mv -i"
# Quick server check
alias ports="sudo ss -tulnp"
alias myip="curl -s ifconfig.me"
# Git shortcuts
alias gs="git status"
alias gc="git commit -m"
alias gp="git push"
alias gl="git log --oneline -20"
# Functions for common tasks
mkcd() { mkdir -p "$1" && cd "$1"; }
extract() {
case "$1" in
*.tar.gz) tar xzf "$1" ;;
*.tar.bz2) tar xjf "$1" ;;
*.zip) unzip "$1" ;;
*.gz) gunzip "$1" ;;
*) echo "Unknown format" ;;
esac
}
4. Clipboard Integration
# Copy command output to clipboard
cat ~/.ssh/id_rsa.pub | xclip -selection clipboard
# Copy file contents
xclip -selection clipboard < file.txt
# Paste from clipboard into command
xclip -selection clipboard -o | grep "pattern"
# On macOS: use pbcopy and pbpaste instead
5. Bang Commands for History Reuse
# Repeat last command
!!
# Run last command with sudo
sudo !!
# Repeat last command starting with specific string
!docker
!ssh
# Use last argument of previous command
mkdir /var/www/newsite
cd !$
# cd /var/www/newsite
# Use all arguments of previous command
echo one two three
printf "%s\n" !*
Bonus: Essential Keyboard Shortcuts
Ctrl+A— Move cursor to beginning of lineCtrl+E— Move cursor to end of lineCtrl+W— Delete word before cursorCtrl+U— Delete from cursor to beginning of lineCtrl+K— Delete from cursor to end of lineCtrl+L— Clear screen (same asclear)Ctrl+Z— Suspend current process (resume withfg)
Practice one shortcut at a time until it becomes muscle memory. Within a week, you will notice a significant improvement in your command-line speed.