
Keyboard Tricks
Think of keyboard tricks in Linux like having a super-powered keyboard that can do more than just type letters. Just like how video games have special key combinations for special moves, Linux gives you powerful shortcuts to work faster and smarter. These tricks help you type less and do more!
Quick Reference
Category | What It Does | Common Use |
---|---|---|
Cursor Movement | Move around in commands | Editing commands quickly |
Text Editing | Modify text in commands | Fixing typos, changing words |
Cut & Paste | Move text around | Reusing parts of commands |
Completion | Auto-complete commands | Typing less, working faster |
History | Reuse past commands | Running commands again |
When to Use Keyboard Tricks
- When you need to edit a long command
- When you want to reuse parts of commands
- When you need to fix typos quickly
- When you want to run previous commands
- When you need to complete long filenames
Cursor Movement
Think of cursor movement commands like having a teleport button for your cursor. Instead of holding down arrow keys, you can jump to exactly where you need to be!
Key | What It Does | When to Use It |
---|---|---|
Ctrl-a |
Go to start of line | When you need to add something at the beginning |
Ctrl-e |
Go to end of line | When you need to add something at the end |
Ctrl-f |
Move forward one character | When you need to move right (same as right arrow) |
Ctrl-b |
Move backward one character | When you need to move left (same as left arrow) |
Alt-f |
Move forward one word | When you need to jump over a word |
Alt-b |
Move backward one word | When you need to jump back a word |
Ctrl-l |
Clear screen | When your screen is cluttered |
Text Editing
Think of text editing commands like having a magic eraser and pen. You can fix mistakes, change words, and transform text without retyping everything!
Key | What It Does | When to Use It |
---|---|---|
Ctrl-d |
Delete character at cursor | When you need to delete one character |
Ctrl-t |
Swap two characters | When you type letters in wrong order |
Alt-t |
Swap two words | When you type words in wrong order |
Alt-l |
Make word lowercase | When you need to fix capitalization |
Alt-u |
Make word uppercase | When you need to capitalize a word |
Cut and Paste (Kill and Yank)
Think of cut and paste commands like having a clipboard for your terminal. You can save parts of commands and use them later!
Key | What It Does | When to Use It |
---|---|---|
Ctrl-k |
Cut to end of line | When you want to save the end of a command |
Ctrl-u |
Cut to start of line | When you want to save the beginning of a command |
Alt-d |
Cut to end of word | When you want to save the end of a word |
Alt-Backspace |
Cut to start of word | When you want to save the beginning of a word |
Ctrl-y |
Paste cut text | When you want to use saved text |
Command Completion
Think of command completion like having an assistant that finishes your sentences. Just type part of a command and let the computer help you complete it! When you press Tab, the shell tries to complete what you're typing based on what it knows about commands, files, and directories.
How Completion Works
# Basic completion
ls D[TAB] → ls Documents/
# When there are multiple matches, press Tab twice
ls D[TAB][TAB]
Documents/ Downloads/ Desktop/
# When there are many matches (over 100), you'll see:
ls *[TAB]
Display all 150 possibilities? (y or n)
# When there are no matches, you'll hear a beep
ls nonexistent[TAB] → *beep*
Smart Completion Features
- Double Tab: When there are multiple possible completions, pressing Tab twice shows all options
- Partial Matches: Type enough characters to make the match unique, then Tab
- Many Matches: When there are over 100 matches, the shell asks before showing them all
- No Matches: The shell beeps to tell you it can't complete what you typed
- Case Sensitive: Completion respects case, so 'D' and 'd' are different
Practical Examples
# Type 'ls D' and press Tab
ls Documents/
# Type 'ls D' and press Tab twice to see all D* matches
ls D[TAB][TAB]
Documents/ Downloads/ Desktop/
# Type 'ls *.txt' and press Tab twice to see all .txt files
ls *.txt[TAB][TAB]
file1.txt file2.txt file3.txt ...
# Type 'cd ~/D' and press Tab
cd ~/Downloads/
# When there are many matches, you'll be asked:
ls *[TAB]
Display all 150 possibilities? (y or n)
# Type 'y' to see all matches, 'n' to cancel
Key | What It Does | When to Use It |
---|---|---|
Tab |
Complete command/filename | When you know part of a name |
Alt-? |
Show all possibilities | When you want to see all options |
Alt-* |
Insert all possibilities | When you want to use all matches |
Command History
Think of command history like having a time machine for your commands. You can go back and reuse any command you've typed before!
Practical Examples
# Run the last command again
!!
# Run command number 88
!88
# Run the last command starting with 'ls'
!ls
# Run the last command containing 'grep'
!?grep
Command | What It Does | When to Use It |
---|---|---|
!! |
Run last command | When you want to run the same command again |
!number |
Run command by number | When you know the command number |
!string |
Run last command starting with string | When you remember how the command started |
!?string |
Run last command containing string | When you remember part of the command |
Tips for Success
- Start with a few basic shortcuts and add more as you get comfortable
- Practice using Tab completion - it's a huge time saver
- Use command history to avoid retyping long commands
- Remember that Alt key combinations might not work in all terminals
- Use
Ctrl-l
to clear your screen when it gets cluttered
Common Mistakes to Avoid
- Forgetting that some shortcuts might be different in different terminals
- Not using Tab completion when it would save time
- Retyping commands that you could get from history
- Using arrow keys when keyboard shortcuts would be faster
- Not practicing the shortcuts enough to remember them
Best Practices
- Learn shortcuts gradually - don't try to memorize them all at once
- Use Tab completion whenever possible
- Use command history for complex commands
- Practice the shortcuts you use most often
- Customize your shortcuts if needed (in .bashrc)
Advanced Techniques
Combining Shortcuts
# Edit a long command: Ctrl-a to start, then edit
# Use Alt-f and Alt-b to move by words
# Use Ctrl-k to cut parts you don't need
# Use Ctrl-y to paste them back if needed
# Use history with completion
!ls *.txt # Run last ls command with .txt files
# Use multiple completions
cd ~/D[TAB] # Complete to Downloads
ls *.txt[TAB] # Show all .txt files