Here are advanced tips for using the terminal efficiently on Linux or Unix-based systems. These will help you boost productivity, automate tasks, and navigate like a power user:
Advanced Terminal Tips & Tricks#
1. Master Bash Shortcuts#
| Shortcut | Action |
|---|---|
Ctrl + A | Move to beginning of line |
Ctrl + E | Move to end of line |
Ctrl + U | Delete from cursor to start |
Ctrl + K | Delete from cursor to end |
Ctrl + R | Search command history interactively |
!! | Run the last command again |
!sudo !! | Run last command with sudo |
2. Use Aliases to Save Time#
Define shortcuts in ~/.bashrc or ~/.zshrc:
alias gs='git status'
alias ll='ls -lah --color=auto'
alias c='clear'
alias ..='cd ..'Then reload with source ~/.bashrc.
3. Use Functions for Complex Tasks#
Example: extract any archive format
extract() {
if [ -f "$1" ]; then
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.zip) unzip "$1" ;;
*.rar) unrar x "$1" ;;
*) echo "Unknown format" ;;
esac
else
echo "'$1' is not a valid file"
fi
}4. Use tmux or screen for Terminal Sessions#
Run long processes without worrying about disconnection
Split terminal windows
Reattach sessions later:
tmux tmux attach
5. Search & Reuse Commands#
history | grep sshOr use reverse search with Ctrl + R, then type a keyword.
6. Jump to Directories Quickly#
Use autojump:
j projectsIt learns your habits and allows you to jump to frequently visited folders.
7. Use Process Substitution#
Compare output of two commands:
diff <(ls /etc) <(ls /usr/etc)8. Copy Output to Clipboard#
Depends on system:
ls | xclip -selection clipboard # Linux (X11)
ls | pbcopy # macOS9. Use xargs Like a Pro#
Example: delete all .bak files
find . -name "*.bak" | xargs rmOr parallel execution:
cat urls.txt | xargs -n 1 -P 10 curl -O10. Customize Your Prompt (PS1)#
Example:
export PS1="\[\e[32m\]\u@\h:\w \$\[\e[0m\] "Try Starship Prompt for a powerful, cross-shell prompt.
11. Run Commands Over SSH Easily#
ssh user@host 'df -h'12. Use tee to View and Save Output#
ls -l | tee output.txt13. Loop Through Commands#
Example: batch rename
for f in *.JPG; do mv "$f" "${f%.JPG}.jpg"; done14. Use Arithmetic#
echo $(( 10 + 5 ))15. Time Commands#
time tar czf archive.tar.gz folder/Bonus Tools#
fzf— Fuzzy finder for files and historybat— Bettercatwith syntax highlightinghtop— Bettertopncdu— Disk usage analyzerripgrep (rg)— Fast recursive grepexa— Modern replacement forls
