Skip to main content

Advanced Terminal Tips and Tricks for Linux

·439 words·3 mins·

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 .