Productivity Tips and Tricks
These tips will make you significantly faster and more efficient on the command line.
Keyboard Shortcuts
Line Editing
| Shortcut | Action |
|---|---|
Ctrl + A | Go to beginning of line |
Ctrl + E | Go to end of line |
Ctrl + U | Delete from cursor to beginning |
Ctrl + K | Delete from cursor to end |
Ctrl + W | Delete word before cursor |
Alt + D | Delete word after cursor |
Ctrl + Y | Paste deleted text |
Command Control
| Shortcut | Action |
|---|---|
Ctrl + C | Cancel current command |
Ctrl + Z | Suspend process (use fg to resume) |
Ctrl + D | Exit shell (or send EOF) |
Ctrl + L | Clear screen |
Ctrl + R | Search command history |
History Tricks
Search History
Ctrl + R # Search as you type
!! # Run last command
!$ # Last argument of last command
!* # All arguments of last command
!n # Run command number n
!string # Run last command starting with string
Example
sudo apt update
sudo !! # Runs: sudo apt update (again)
cat file.txt
vim !$ # Runs: vim file.txt
Tab Completion
The Tab key is your friend:
- Tab once: Complete if unique
- Tab twice: Show all options
Works for:
- Commands
- File paths
- Options (with some commands)
- Hostnames
Brace Expansion
Create multiple items efficiently:
# Create multiple files
touch file{1,2,3}.txt
# Creates: file1.txt file2.txt file3.txt
# Create range
mkdir day{01..31}
# Creates: day01, day02, ... day31
# Multiple expansions
cp file.{txt,bak}
# Same as: cp file.txt file.bak
Exercise: Use Brace Expansion
Create multiple files at once:
Aliases
Create shortcuts for common commands:
# Add to ~/.bashrc
alias ll='ls -la'
alias la='ls -A'
alias l='ls -CF'
alias ..='cd ..'
alias ...='cd ../..'
alias update='sudo apt update && sudo apt upgrade -y'
alias gs='git status'
alias gc='git commit'
Quick Editing
# Edit last command in editor
fc
# Edit and re-run
^old^new # Replace old with new in last command
Working with Output
# Save and display
command | tee file.txt
# Clipboard (requires xclip)
command | xclip -selection clipboard
# Count results
command | wc -l
Process Shortcuts
# Run in background
command &
# Suspend and background
Ctrl + Z
bg
# Bring to foreground
fg
Time Savers
Previous Directory
cd - # Go to previous directory
Make and Enter Directory
mkdir newdir && cd newdir
# Or create a function:
mkcd() { mkdir -p "$1" && cd "$1"; }
Safe rm
alias rm='rm -i' # Always ask
Quick Server
python3 -m http.server 8000
File Quick Actions
# Quick backup
cp file.txt{,.bak} # Creates file.txt.bak
# Swap two files
mv file1 temp && mv file2 file1 && mv temp file2
Multiple Commands
# Run in sequence
cmd1 ; cmd2 ; cmd3
# Run only if previous succeeds
cmd1 && cmd2 && cmd3
# Run only if previous fails
cmd1 || cmd2
Glob Patterns
* # Any characters
? # Single character
[abc] # a, b, or c
[0-9] # Digit
** # Recursive (with shopt -s globstar)
Key Takeaways
- Learn keyboard shortcuts (Ctrl+A, Ctrl+E, Ctrl+R)
- Use Tab completion constantly
- Create aliases for common commands
- Brace expansion saves typing
- History search (
Ctrl+R) finds previous commands !!and!$reuse command history
التالي · الدرس 40 من 40
Practice Challenges
قراءة 1 دقيقة
أنهيت 39 من 40 درسًا

اسأل Byte عن هذا الدرس
محادثة خاصة حول هذا الدرس. قرأ Byte الدرس كاملًا، ويجيب خلال ثوانٍ، ويُظهر القسم الذي تأتي منه كل إجابة. يمكنك السؤال بأي لغة.
الأسئلة والأجوبة
أسئلة عامة حول هذا الدرس. يجيب AI Tutor فورًا بلغتك، ويراجع فريق FreeAcademy الإجابات، ويمكن لكل المتعلمين قراءتها.

