Skip to main content

Advanced Terminal Tips and Tricks for Linux

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
#

ShortcutAction
Ctrl + AMove to beginning of line
Ctrl + EMove to end of line
Ctrl + UDelete from cursor to start
Ctrl + KDelete from cursor to end
Ctrl + RSearch 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 ssh

Or use reverse search with Ctrl + R, then type a keyword.


๐Ÿ“ 6. Jump to Directories Quickly
#

Use autojump:

j projects

It 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 rm

Or 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 history
  • bat โ€” Better cat with syntax highlighting
  • htop โ€” Better top
  • ncdu โ€” Disk usage analyzer
  • ripgrep (rg) โ€” Fast recursive grep
  • exa โ€” Modern replacement for ls

Youcef
Author
Youcef
My name is youcef and i’m linux user who fool in love with linux , like free and open software .