Linux Terminal Tricks That Save Time
In this article
- Why the Terminal Feels Slow
- Tab Completion: The Biggest Time Saver
- History: Reuse, Don't Retype
- Editing Commands Without Retyping
- Aliases and Functions: Shorten Repeated Commands
- Navigating Faster with pushd and popd
- Brace Expansion and Wildcards
- Common Problems and Pitfalls
- Alternatives and Advanced Tools
- Frequently Asked Questions
The fastest way to save time in the Linux terminal is to stop typing long commands and start using shell history, tab completion, and keyboard shortcuts. These built-in features work in every shell and require no extra software, making them the first things to master for anyone who spends time on the command line.
Why the Terminal Feels Slow
Most people type the same long commands over and over, or they re-type a command with a small change because they do not know the shell keeps a history. The terminal is not slow; the user is repeating work the shell can do automatically. Learning a few shortcuts turns minutes of typing into seconds of editing.
Tab Completion: The Biggest Time Saver
Pressing Tab completes file names, directories, and command names. If you type cd /us and press Tab, it becomes cd /usr/. Pressing Tab twice shows all matches. This alone removes most typing errors and long path entries.
- Complete a command: type
sysand Tab to getsystemctl. - Complete a file path: type
cd ~/Docand Tab to getcd ~/Documents/. - List matches: press Tab twice to see all options.
In bash, you can also use ** for recursive completion if you enable globstar with shopt -s globstar.
History: Reuse, Don't Retype
The shell remembers every command you type. Use the up and down arrow keys to scroll through previous commands. To search, press Ctrl+R and type part of a command; the shell shows the most recent match. Press Ctrl+R again to cycle through older matches.
!!repeats the last command.!$expands to the last argument of the previous command.!lsruns the most recent command starting withls.
For example, after mkdir newproject, type cd !$ to go into that directory without retyping its name.
Editing Commands Without Retyping
When you press Up to get a previous command, you can edit it using shortcuts that work like in a text editor.
Ctrl+A– go to the beginning of the line.Ctrl+E– go to the end of the line.Alt+B/Alt+F– move back/forward one word.Ctrl+W– delete the previous word.Ctrl+U– delete everything before the cursor.Ctrl+K– delete everything after the cursor.
These shortcuts work in bash, zsh, and most default shells. They turn a long, error-prone command into a quick edit.
Aliases and Functions: Shorten Repeated Commands
If you type the same long command often, create an alias. Add lines to your ~/.bashrc (or ~/.zshrc for zsh):
alias ll='ls -alF'
alias gs='git status'
alias ..='cd ..'After saving, run source ~/.bashrc to apply the changes. For more complex commands, use a function:
mkcd() { mkdir -p "$1" && cd "$1"; }Now mkcd newfolder creates a directory and enters it in one step.
Navigating Faster with pushd and popd
Instead of typing long cd paths back and forth, use a directory stack.
pushd /path/to/dir– saves the current directory and changes to the new one.popd– returns to the saved directory.dirs– shows the stack.
For example, if you are in /home/user/project and need to check a file in /etc, type pushd /etc, then popd to return. This avoids retyping the full path.
Brace Expansion and Wildcards
Brace expansion generates multiple arguments from one pattern. For example, mkdir {jan,feb,mar}_report creates three directories at once. Wildcards like * and ? match files without typing full names.
rm *.log– delete all files ending in.log.cp report{,.bak}– copiesreporttoreport.bak.touch file{1..5}.txt– creates five files: file1.txt to file5.txt.
These patterns save time when dealing with multiple files.
Common Problems and Pitfalls
One common mistake is using sudo with aliases, because aliases do not expand by default with sudo. To fix, define the alias with the full command or use sudo !! to run the last command with sudo.
Another issue is that Ctrl+R search can be slow if your history file is huge. You can limit history size in .bashrc with HISTSIZE=1000 and HISTFILESIZE=2000.
Also, be careful with rm and wildcards. rm *.txt removes all text files in the current directory; there is no undo. Always double-check the pattern with ls first.
Alternatives and Advanced Tools
If you want more than the default shell, consider using zsh with the oh-my-zsh framework, which offers better tab completion and many plugins. Tools like fzf (fuzzy finder) let you search history and files interactively with Ctrl+R and Ctrl+T. These are not required, but they can further speed up your workflow.
Frequently Asked Questions
How do I make tab completion case-insensitive?
In bash, add set completion-ignore-case on to your ~/.inputrc and restart the terminal. This makes cd de match Desktop as well as desktop.
Why doesn't my alias work in scripts?
Aliases are not expanded in non-interactive shells by default. In a script, use a function or the full command. For example, define ll() { ls -alF; } instead of an alias.
How do I undo a command I just ran?
There is no general undo for command-line actions. If you deleted a file, you might recover it from a backup or use extundelete on ext filesystems, but that is not guaranteed. Always be careful with destructive commands.
What is the difference between bash and zsh shortcuts?
Most basic shortcuts like Ctrl+A and Ctrl+E are the same. zsh has additional features like better globbing and more advanced completion, but the core editing shortcuts are identical because they follow the readline library.
Can I use these tricks in a GUI terminal emulator?
Yes, they work in any terminal emulator (GNOME Terminal, Konsole, xterm, etc.) because they are features of the shell, not the terminal program.