Introduction
If you spend a significant amount of time in the terminal, even small productivity gains compound into hours saved each week. I've curated 10 practical tips that have transformed my workflow. No fluff, just actionable advice.
1. Master Keyboard Shortcuts
Learn these core shortcuts for bash/zsh:
-
Ctrl + a/Ctrl + e: Jump to beginning/end of line. -
Ctrl + u/Ctrl + k: Delete from cursor to start/end of line. -
Ctrl + w: Delete word backward. -
Ctrl + r: Reverse search through command history. -
Ctrl + l: Clear screen (instead of typingclear).
Practice until they become muscle memory. This alone will save you minutes daily.
2. Use Aliases for Frequent Commands
Aliases turn long commands into short ones. Add these to your ~/.bashrc or ~/.zshrc:
# Common shortcuts
alias ll='ls -lah'
alias gs='git status'
alias gc='git commit'
alias ..='cd ..'
alias ...='cd ../..'
# Safe file operations
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
Reload with source ~/.bashrc.
3. Leverage Tab Completion
Most shells support tab completion for commands, files, and arguments. For example:
- Type
cd Docand press Tab to auto-complete tocd Documents/. - With
git checkoutpress Tab twice to see branch names.
Enable case-insensitive completion if needed:
bind "set completion-ignore-case on"
4. Navigate with cd and pushd/popd
Stop typing long paths. Use pushd and popd to maintain a directory stack:
pushd /var/log # save current dir and go to /var/log
popd # return to previous dir
For quick jumps, use cd - to toggle between two directories.
5. Search and Reuse Commands with History
-
historyshows recent commands with numbers. -
!123re-runs command number 123. -
!!re-runs the last command (useful withsudo !!). -
Ctrl + rtriggers reverse search; type a keyword and pressCtrl + rrepeatedly to cycle through matches.
6. Process Management
-
Ctrl + z: Suspend the current foreground job. -
fg: Resume the suspended job in the foreground. -
bg: Resume it in the background. -
jobs: List all background jobs.
Example: You start editing a file with vim, then press Ctrl + z, run other commands, and type fg to return to vim.
7. Use grep and find Efficiently
-
grep -r "pattern" .searches recursively in current directory. -
grep -rn "pattern" .adds line numbers. -
find . -name "*.py"finds Python files. - Combine with
-execto act on results:find . -name "*.log" -exec rm {} \;
8. Pipe and Redirect Like a Pro
-
command1 | command2: Pipe output of command1 to command2. -
> fileredirects stdout to file (overwrites). -
>> fileappends stdout. -
2>&1merges stderr into stdout:command > output.txt 2>&1. -
&>is a bash shortcut:command &> output.txt.
9. Customize Your Prompt
A useful prompt shows current directory, git branch, and exit status. Example for bash:
PS1='\[\e[0;32m\]\u@\h \[\e[0;33m\]\w\[\e[0m\]$(__git_ps1 " (%s)") \$ '
For zsh, use themes like agnoster or powerlevel10k.
10. Script Repetitive Tasks
Instead of typing multiple commands, write a script. For example, a backup script:
#!/bin/bash
backup_dir="$HOME/backups/$(date +%Y%m%d)"
mkdir -p "$backup_dir"
cp -r ~/Documents "$backup_dir"
echo "Backup done to $backup_dir"
Save as backup.sh, make executable with chmod +x backup.sh, and run it whenever needed.
Conclusion
These tips are easy to implement and will make you significantly faster in the terminal. Start with one or two, and gradually incorporate more. Happy hacking!
Top comments (0)