100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Bash

Linux & Shell Quick Reference

A condensed cheat sheet consolidating the most frequently used Linux commands, Bash syntax, and shortcuts covered throughout this course for fast lookup.

Interview PrepBeginner9 min readJul 9, 2026
Analogies

Linux & Shell Quick Reference

This reference consolidates the highest-frequency commands and syntax patterns from across the course into one scannable page. It is intentionally terse — the goal is fast lookup during real work, not re-teaching concepts already covered in depth elsewhere. Each subsection groups related commands so you can jump directly to filesystem navigation, text processing, process management, permissions, or Bash scripting syntax without hunting through prose.

🏏

Cricket analogy: This section is like a cricket almanac's quick-stats page — not full match reports, just career averages and records grouped by batting, bowling, and fielding so you can look up a fact fast during a broadcast.

Filesystem Navigation and File Operations

These commands form the backbone of interactive shell use: moving around the tree, inspecting metadata, and manipulating files and directories.

🏏

Cricket analogy: These are the basics every player drills first — footwork, grip, and stance — the fundamentals you use in every single innings before anything fancier.

bash
pwd                          # print working directory
cd /path/to/dir              # change directory
cd -                         # go to previous directory
cd ~                         # go to home directory
ls -lah                      # long listing, all files, human-readable sizes
find /var/log -name "*.log" -mtime +7   # files matching name, older than 7 days
locate nginx.conf            # fast indexed search (requires updatedb)
cp -r src/ dest/              # copy recursively
mv old_name new_name          # move or rename
rm -rf dir/                   # remove recursively, forced (dangerous)
mkdir -p a/b/c                # create nested directories
ln -s /path/target linkname   # create symbolic link
tar -czvf archive.tar.gz dir/ # create compressed archive
tar -xzvf archive.tar.gz      # extract compressed archive

Text Processing and Searching

The core Unix text toolkit — grep, sed, awk, sort, cut, and friends — combined via pipes to filter, transform, and summarize data streams.

🏏

Cricket analogy: grep is like scanning the scorecard for every over bowled by a specific bowler; sed is like correcting a misprinted player's name across the whole scoresheet; awk is like calculating strike rate from raw ball-by-ball columns, and piping them together builds a full analysis from raw match data.

bash
grep -rn "TODO" ./src/        # recursive, line-numbered search
grep -v "^#"  config.conf     # invert match, exclude comment lines
sed 's/foo/bar/g' file.txt    # replace all occurrences of foo with bar
sed -i.bak 's/old/new/' f.txt # in-place edit with backup file
awk -F',' '{print $1, $3}' data.csv   # print columns 1 and 3, comma-delimited
sort -k2 -n file.txt          # sort numerically by 2nd field
cut -d':' -f1 /etc/passwd     # extract 1st colon-delimited field
uniq -c                       # count adjacent duplicate lines (pair with sort first)
wc -l file.txt                # count lines
tail -f /var/log/syslog       # follow a growing file live
xargs -I{} rm {}              # build/execute commands from stdin

Processes, Permissions, and System Info

Commands for inspecting and controlling running processes, managing ownership and access, and checking system resource usage.

🏏

Cricket analogy: These tools are like a team analyst checking who's currently batting, who's authorized to make bowling changes, and how much stamina the bowlers have left in the tank.

bash
ps aux | grep nginx            # list processes matching 'nginx'
top / htop                     # live process/resource monitor
kill -15 <pid>                 # graceful termination (SIGTERM)
kill -9 <pid>                  # forceful termination (SIGKILL)
nohup ./long_task.sh &         # run in background, immune to hangup
jobs -l                        # list background jobs in current shell
chmod 755 script.sh            # rwxr-xr-x
chmod u+x script.sh            # add execute for owner only
chown user:group file.txt      # change owner and group
sudo -l                        # list current user's sudo privileges
df -h                          # filesystem free space
du -sh dir/                    # total size of a directory
free -h                        # memory usage
uptime                         # load average and uptime

GNU tools (found on most Linux distros) and BSD tools (found on macOS by default) diverge in flag behavior — most notably sed -i requires a backup suffix argument on BSD/macOS (sed -i '' 's/a/b/') but not on GNU/Linux (sed -i 's/a/b/'). Scripts intended to be portable across both should either detect the platform or use sed -i.bak consistently, which works on both (leaving a .bak file to clean up).

Bash Scripting Syntax Cheat Sheet

The syntax patterns used in nearly every non-trivial script: conditionals, loops, functions, and parameter handling.

🏏

Cricket analogy: This is the playbook of decision rules a captain uses in nearly every match — when to review, when to rotate bowlers, and set fielding routines — the recurring patterns behind almost every tactical call.

bash
#!/usr/bin/env bash
set -euo pipefail

# Variables and quoting
name="World"
echo "Hello, $name!"

# Conditionals
if [[ -f "$1" ]]; then
    echo "File exists"
elif [[ -d "$1" ]]; then
    echo "Directory exists"
else
    echo "Not found"
fi

# Loops
for f in *.log; do
    echo "Processing $f"
done

while read -r line; do
    echo "$line"
done < input.txt

# Functions
greet() {
    local who="$1"
    echo "Hi, $who"
}
greet "Alice"

# Arrays
fruits=("apple" "banana" "cherry")
echo "${fruits[@]}"       # all elements
echo "${#fruits[@]}"      # array length

# Command-line args and getopts
while getopts "f:v" opt; do
    case "$opt" in
        f) file="$OPTARG" ;;
        v) verbose=1 ;;
        *) echo "Usage: $0 [-f file] [-v]"; exit 1 ;;
    esac
done

# Exit codes
command_that_might_fail
echo "Exit status: $?"

Networking, Package Management, and Scheduling

Quick-reference commands for the operational tasks that come up outside of pure file/text manipulation: checking connectivity, managing packages, and scheduling recurring jobs.

🏏

Cricket analogy: These are the ground-logistics tasks beyond the actual match — checking the pitch report, ordering new equipment, and scheduling the next fixture.

bash
# Networking
ip a                            # show network interfaces and addresses
ss -tulpn                       # listening TCP/UDP sockets with process info
ping -c 4 example.com           # test connectivity, 4 packets
curl -I https://example.com     # fetch HTTP headers only
ssh user@host                   # remote shell
scp file.txt user@host:/path/   # copy file to remote host

# Package management (Debian/Ubuntu vs RHEL/CentOS)
sudo apt update && sudo apt install -y curl   # Debian/Ubuntu
sudo yum install -y curl                       # RHEL/CentOS (older)
sudo dnf install -y curl                       # RHEL/Fedora (newer)

# Scheduling
crontab -e                       # edit current user's crontab
crontab -l                       # list current user's cron jobs
# m h dom mon dow command
0 3 * * * /opt/scripts/backup.sh >> /var/log/backup.log 2>&1

systemctl status nginx           # check service status
systemctl restart nginx          # restart a service
systemctl enable nginx           # enable service at boot
journalctl -u nginx -f           # follow logs for a service

This page is a memory aid, not a substitute for reading the full lessons on each topic — flags like chmod 755 or rm -rf are dangerous when copy-pasted without understanding what they do in your specific context. Always confirm the target path/permissions before running destructive or permission-altering commands, especially when adapting an example from a cheat sheet to a live production system.

  • This page is organized by task category (navigation, text processing, processes/permissions, scripting syntax, networking/packages/scheduling) for fast lookup.
  • grep, sed, awk, sort, cut, and uniq combined via pipes cover the vast majority of everyday text-processing needs.
  • chmod/chown control permissions and ownership; ps/top/kill control process inspection and lifecycle; df/du/free cover resource usage.
  • A safe Bash script header is #!/usr/bin/env bash plus set -euo pipefail, with all variable expansions quoted.
  • Package management commands differ by distro family: apt for Debian/Ubuntu, yum/dnf for RHEL/CentOS/Fedora.
  • Always verify destructive commands (rm -rf, chmod, kill -9) against the specific context before running them — a cheat sheet is a memory aid, not a substitute for understanding.

Practice what you learned

Was this page helpful?

Topics covered

#Bash#LinuxShellScriptingStudyNotes#DevOps#LinuxShellQuickReference#Linux#Shell#Quick#Reference#StudyNotes#SkillVeris