The Bash shell is a powerful tool that allows you to efficiently interact with your Linux system. However, Bash offers many shortcuts and techniques that allow you to boost your productivity even further when working in the terminal. Mastering these Bash shortcuts can help you save significant time and effort in your day-to-day terminal use.
In this article, we will explore some of the most useful Bash shortcuts and productivity techniques:
Navigation Shortcuts
Navigation in Bash is a core part of working efficiently. Here are some shortcuts to quickly navigate the terminal:
Ctrl + A
- Go to the beginning of the lineCtrl + E
- Go to the end of the lineAlt + B
- Move backward one wordAlt + F
- Move forward one wordCtrl + XX
- Toggle between the start of line and current cursor position
Using these shortcuts allows you to quickly jump around the current command line to make edits.
Command History Shortcuts
Bash saves a history of all commands you have previously entered. Leveraging this history can save you from retyping frequent commands.
Ctrl + R
- Search through command history!!
- Repeat last command!string
- Repeat last command starting with 'string'!?string?
- Repeat last command containing 'string'
Search through your history and reuse commands instead of retyping.
Text Editing Shortcuts
Editing text on the command line is faster with these shortcuts:
Ctrl + W
- Delete last wordCtrl + U
- Delete entire lineAlt + D
- Delete all characters after cursorAlt + T
- Swap current word with previous word
Quickly fix typos and errors in the current command.
Job Control Shortcuts
Manage running jobs efficiently:
Ctrl + C
- Kill current foreground jobCtrl + Z
- Suspend current foreground jobfg
- Restore suspended job to foregroundbg
- Restore suspended job to running in background
Juggle multiple running processes without starting over.
Tab Completion
One of the most useful Bash productivity features is tab completion. Pressing tab at any point in a command will auto-complete filenames, command names, variables, and more.
Some examples:
cd /hom<tab>
- Autocompletes to/home/
mv file<tab>
- Autocompletes filenamegit comm<tab>
- Autocompletes togit commit
Spend less time typing and use tab for instant auto-completion.
Set Shortcut Aliases
For commonly used commands, set shortcut aliases in your ~/.bashrc
file:
alias ll='ls -lah'
alias ..='cd ..'
Then use ll
in place of ls -lah
and ..
to quickly go up a directory. Come up with your own aliases to save typing for common commands.
Functions for Command Sequences
For a series of commands you run together, write them into a function for easy reuse:
function mkd() {
mkdir -p "$1"
cd "$1"
}
Now you can just run mkd foldername
to make a directory and cd into it.
Dotfiles for Customization
Use your dotfiles like .bash_profile
and .bashrc
to customize your environment. Set shortcuts, aliases, functions, and Bash settings to optimize your workflow.
Version control your dotfiles to keep your customizations consistent across systems.
Conclusion
Learning Bash shortcuts and techniques can significantly boost your productivity working on the Linux command line. Master shortcuts for navigation, command history, editing, job control, and tab completion. Customize your environment with aliases, functions, and dotfiles. Use options for readability and chain together commands with pipes. Bash offers many built-in tools waiting for you to utilize them!