Source: Bash Essentials — Connected Objects

Key Keyboard Shortcuts

ShortcutAction
Ctrl+rReverse history search (recall previous command)
Ctrl+cKill/interrupt running process (SIGINT)
Ctrl+zSuspend process (SIGTSTP) — resume with fg
Ctrl+dSend EOF / close shell
Ctrl+lClear screen
Ctrl+aGo to beginning of line
Ctrl+eGo to end of line
Ctrl+wCut word before cursor
Ctrl+kCut to end of line
Ctrl+yPaste (yank)
TABAutocomplete file/directory names
Alt+b/fMove backward/forward one word

Config Files

FileWhen loadedTypical use
~/.bashrcEvery new terminal windowaliases, env vars, shell options
~/.profileEvery loginPATH changes, session-wide vars
~/.inputrcReadline startuptab-completion behavior, key bindings
# Example .bashrc
alias ll="ls -l"
export EDITOR="code"
export PS1='[\u@\h:\w]\$ '    # custom prompt

Reload 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 field

3. 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 occurrences

4. 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 onward

5. 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 sudo

Redirection 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 stdout

Key: tee is the solution when sudo command > file fails (permission issue):

echo "1" | sudo tee /sys/class/leds/usr_led0/brightness

Core 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 host

rsync — 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 remote

Only 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 directory

See Also