Shell Tips¶
Keyboard shortcuts and tips for working more efficiently in the shell.
Command History¶
Navigate and reuse previous commands:
Key |
Action |
|---|---|
↑ / ↓ |
Cycle through command history |
Ctrl + R |
Reverse search history |
|
Gets replaced by the last command line |
|
Gets replaced by last argument of previous command line |
|
Gets replaced by the X’th argument of previous command line |
Auto-Completion¶
Speed up typing with tab completion:
Press Tab to auto-complete file and directory names
Press Tab twice to see all available options
Works for commands, files, directories, and users
Controlling Commands¶
Manage running processes:
Key |
Action |
|---|---|
Ctrl + C |
Kill current command |
Ctrl + Z |
Pause current process (resume with |
Ctrl + D Or |
Exit current shell |
Ctrl + L |
Same as running |
Command Line Editing¶
Edit commands before running:
Key |
Action |
|---|---|
Ctrl + A |
Move to beginning of line |
Ctrl + E |
Move to end of line |
Ctrl + U |
Cut from cursor to beginning |
Ctrl + K |
Cut from cursor to end |
Ctrl + W |
Cut word before cursor |
Quick Tips¶
# Run command in background
command &
# Bring background job to foreground
fg
# List background jobs
jobs
# Redirect output to file
command > output.txt
# Append output to file
command >> output.txt
# Combine commands
command1 && command2 # Run command2 only if command1 succeeds
command1 || command2 # Run command2 only if command1 fails
command1 ; command2 # Run command2 regardless of command1
History Management¶
history # Show command history
history 10 # Show last 10 commands
!123 # Run command #123 from history
!grep # Run last command starting with 'grep'
Tips¶
Add
export HISTSIZE=10000to~/.bashrcto keep more historyUse
!!to quickly repeat a command you just ran