A few years ago, I wasted hours scrolling through command history, retyping long file paths, and fixing typos the slow way. Then I discovered Bash keyboard shortcuts.
After incorporating just a handful of these, my terminal speed doubled.
If you're still using Bash inefficiently, this guide will show you the shortcuts that experienced Linux users rely on dailyโfrom basic navigation to power-user tricks.
1. Rerun the Last Command Instantly (!!
)
Skill Level: Beginner
Instead of retyping a failed command with sudo
, just use:
sudo !!
๐น Real-World Use Case: Quickly retry failed commands without retyping everything.
2. Edit and Reuse the Last Argument (!$
)
Skill Level: Intermediate
Instead of manually copying the last argument:
mv file1.txt /backup/
ls -l !$
This expands to:
ls -l /backup/file1.txt
๐น Real-World Use Case: Saves keystrokes when working with long filenames.
3. Search Command History Like a Pro (Ctrl + R
)
Skill Level: Intermediate
Stop pressing Up Arrow 20 timesโuse reverse search:
- Press
Ctrl + R
- Start typing a previous command
- Press
Enter
to run it instantly
๐น Real-World Use Case: Instantly finds a complex command without scrolling through history.
4. Move to the Beginning or End of a Command (Ctrl + A / Ctrl + E
)
Skill Level: Beginner
Stop holding Left Arrow to edit a command. Use:
-
Ctrl + A
โ Jump to the start -
Ctrl + E
โ Jump to the end
๐น Real-World Use Case: Makes editing long commands much faster.
5. Delete a Whole Line (Ctrl + U
)
Skill Level: Intermediate
Instead of holding Backspace, erase everything before the cursor instantly:
Ctrl + U
๐น Real-World Use Case: Quickly clear mistakes without retyping everything.
6. Delete Everything After the Cursor (Ctrl + K
)
Skill Level: Intermediate
echo "This is a test sentence"
If the cursor is after "test", pressing Ctrl + K
results in:
echo "This is a test"
๐น Real-World Use Case: Remove unnecessary text without deleting the whole command.
7. Swap Two Characters (Ctrl + T
)
Skill Level: Advanced
Instead of manually fixing typos:
grpe file.txt # Typo
Press Ctrl + T
:
grep file.txt # Fixed
๐น Real-World Use Case: Quick typo correction without retyping.
8. Cancel a Running Command (Ctrl + C
)
Skill Level: Beginner
Stops a command immediately.
ping google.com
# Press Ctrl + C to stop
๐น Real-World Use Case: Kills unresponsive processes instantly.
9. Suspend a Process (Ctrl + Z
)
Skill Level: Advanced
Pause a running task instead of quitting it:
vim file.txt # Press Ctrl + Z
Resume later with:
fg
๐น Real-World Use Case: Temporarily switch tasks without losing progress.
10. Run a Process in the Background (&
)
Skill Level: Intermediate
long-running-task.sh &
๐น Real-World Use Case: Keeps the terminal free while running background tasks.
11. Kill a Background Process (jobs
+ kill %
)
Skill Level: Advanced
List background jobs:
jobs
Kill job #2:
kill %2
๐น Real-World Use Case: Manages multiple background tasks efficiently.
12. Clear the Terminal (Ctrl + L
)
Skill Level: Beginner
Same as clear
, but faster.
Ctrl + L
๐น Real-World Use Case: Keeps your workspace clean.
13. Copy the Previous Command Without Running It (!:
)
Skill Level: Advanced
Instead of retyping a long command, use !:p
to print the last command without running it.
!:
๐น Real-World Use Case: Preview a command before executing it again.
14. Replace Text in the Last Command (^old^new
)
Skill Level: Intermediate
Instead of retyping a command to fix a mistake:
ls /ect
^ect^etc
๐น Real-World Use Case: Fixes typos without manually editing the command.
15. Scroll Through Past Commands (Up
and Down
)
Skill Level: Beginner
Navigate command history without retyping.
Up Arrow โ Previous command
Down Arrow โ Next command
๐น Real-World Use Case: Quickly re-execute previous commands.
16. Autocomplete File and Command Names (Tab
)
Skill Level: Beginner
Type part of a filename or command, then press Tab
to autocomplete.
ls /var/lo<Tab> # Expands to /var/log
๐น Real-World Use Case: Reduces typing mistakes.
17. Ignore Duplicate Commands in History (HISTCONTROL
)
Skill Level: Advanced
Add this to your .bashrc
to prevent duplicate history entries:
export HISTCONTROL=ignoredups
๐น Real-World Use Case: Keeps history cleaner.
18. Repeat the First Argument of the Last Command (!^
)
Skill Level: Advanced
cp myfile.txt backup/
mv !^ newlocation/
๐น Real-World Use Case: Saves keystrokes and reduces mistakes.
Final Thoughts: Save Hours with Bash Shortcuts
Mastering these shortcuts will speed up your workflow, reduce errors, and make you more efficient in the terminal.
Want a Structured Bash Reference?
If you need a Beginner Friendly Bash guide with easy to follow tips and explanations, check out my Bash Cheat Sheet:
๐ Download the Bash Cheat Sheet for just $3.99
Discussion: Whatโs Your Favorite Bash Shortcut?
Drop a comment below and share your most-used Bash keyboard shortcut!
Top comments (1)
Your example 2, the "edit(?) and reuse..." one, has a typo:
will execute
rm /backup/
, notrm file1.txt
.