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 # macOSโ๏ธ 9. 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 -O๐ 10. 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.txt๐ 13. Loop Through Commands#
Example: batch rename
for f in *.JPG; do mv "$f" "${f%.JPG}.jpg"; done๐งฎ 14. 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
