Source: Bash Essentials — Connected Objects
Key Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Ctrl+r | Reverse history search (recall previous command) |
Ctrl+c | Kill/interrupt running process (SIGINT) |
Ctrl+z | Suspend process (SIGTSTP) — resume with fg |
Ctrl+d | Send EOF / close shell |
Ctrl+l | Clear screen |
Ctrl+a | Go to beginning of line |
Ctrl+e | Go to end of line |
Ctrl+w | Cut word before cursor |
Ctrl+k | Cut to end of line |
Ctrl+y | Paste (yank) |
TAB | Autocomplete file/directory names |
Alt+b/f | Move backward/forward one word |
Config Files
| File | When loaded | Typical use |
|---|---|---|
~/.bashrc | Every new terminal window | aliases, env vars, shell options |
~/.profile | Every login | PATH changes, session-wide vars |
~/.inputrc | Readline startup | tab-completion behavior, key bindings |
# Example .bashrc
alias ll="ls -l"
export EDITOR="code"
export PS1='[\u@\h:\w]\$ ' # custom promptReload without restarting terminal: source ~/.bashrc
The Five Fingers of Death
1. find + grep
# find: search files matching criteria
find . -name '*.py' # all .py files recursively
find . -name '*.png' -delete # find and delete
find . -perm 664 -or -name '*.log' # OR condition
# grep: search file contents
grep "pattern" file.txt # basic search
grep -i "word" file.txt # case-insensitive
grep -n "word" file.txt # show line numbers
grep -r "word" /path/to/dir/ # recursive
grep -v "word" file.txt # invert (exclude)
grep -c "word" file.txt # count matches
grep "word" *.txt # multiple files (wildcard)2. tr + cut
# tr: translate/delete/squeeze characters
echo 'HELLO WORLD' | tr 'A-Z' 'a-z' # lowercase
echo 'hello' | tr 'a-z' 'A-Z' # uppercase
echo '2024-08-12' | tr -d '-' # delete chars → 20240812
echo 'hello world' | tr -s ' ' # squeeze spaces → hello world
# cut: extract columns/fields
cut -f2 file.tsv # 2nd tab-separated field
cut -f1,3 file.tsv # 1st and 3rd fields
cut -f2-4 file.tsv # fields 2 through 4
cut -d',' -f2 file.csv # comma delimiter, 2nd field3. sort + uniq
# sort
sort file.txt # alphabetical ascending
sort -r file.txt # reverse
sort -n file.txt # numeric sort
sort -u file.txt # sort + remove duplicates
# uniq (works on adjacent lines — always sort first)
sort file.txt | uniq # remove duplicates
sort file.txt | uniq -d # show only duplicates
sort file.txt | uniq -u # show only unique lines
sort file.txt | uniq -c # count occurrences4. head + tail
head file.txt # first 10 lines
head -n 5 file.txt # first 5 lines
tail file.txt # last 10 lines
tail -n 5 file.txt # last 5 lines
tail -f file.txt # follow (live updates)
head -n -3 file.txt # all except last 3 lines
tail -n +5 file.txt # all from line 5 onward5. tree + tee
tree # directory tree (current dir)
tree -L 2 # max 2 levels deep
# tee: copy stdin to file AND stdout (both simultaneously)
command | tee output.txt # write to file + show on screen
echo "value" | sudo tee /sys/class/leds/usr_led0/brightness # tee with sudoRedirection and Pipes
command > filename # redirect stdout to file (overwrite)
command >> filename # redirect stdout to file (append)
command < filename # redirect file to stdin
command 2> /dev/null # discard stderr
command > /dev/null # discard stdout
command >&2 # redirect stdout to stderr
commandA | commandB # pipe stdout of A to stdin of B
commandA | tee file # pipe to file AND stdoutKey: tee is the solution when sudo command > file fails (permission issue):
echo "1" | sudo tee /sys/class/leds/usr_led0/brightnessCore Utilities
ssh — Remote Login
ssh user@hostname # connect to remote host
ssh user@192.168.1.100 # connect by IP
ssh user@host "command" # run command on remote hostrsync — Efficient File Transfer
rsync [OPTIONS] SRC DEST
rsync -av src/ user@host:dest/ # push to remote (verbose, archive)
rsync -av user@host:src/ dest/ # pull from remoteOnly transfers differences (efficient for repeated syncs).
tar + zip — Archives
# Create
tar -czf archive.tar.gz folder/ # compress with gzip
tar -cjf archive.tar.bz2 folder/ # compress with bzip2
zip -r archive.zip folder/ # zip
# Extract
tar -xzf archive.tar.gz # extract gzip
tar -xjf archive.tar.bz2 # extract bzip2
unzip archive.zip # extract zip
unzip archive.zip -d ~/output/ # extract to specific dir
tar -czf archive.tar.gz folder/ # shorthand: -c create, -z gzip, -f file
tar -xzf archive.tar.gz -C ~/dest/ # -C specifies output directorySee Also
- Linux and Bash Commands topic
- Bash Scripting topic