contentintech
Beginner

Linux Fundamentals Cheatsheet

Quick reference for Linux — navigation, permissions and ownership, process and service control, package managers, networking, text processing, pipes and redirection, and SSH.

PermissionsProcessesShellNetworking
NotesCheatsheet

Navigation & Files

Moving Around

pwd                  # where am I
ls -lah              # list all, long, human sizes
cd /path  cd -  cd ~ # go, back, home
tree -L 2            # directory tree, 2 levels
stat file            # metadata (size, perms, times)

Manage Files

cp -r src dst        # copy recursively
mv old new           # move / rename
rm -rf dir           # delete recursively (careful)
mkdir -p a/b/c       # create nested dirs
ln -s target link    # symbolic link
touch file           # create empty / update mtime

Permissions & Ownership

Octal Modes

Octal Symbolic Use
755rwxr-xr-xexecutables, dirs
644rw-r--r--config, text
700rwx------private dir
600rw-------SSH keys, secrets
chmod 644 file        # set octal mode
chmod +x script.sh    # add execute
chmod -R 755 dir      # recursive
chown user:group file # change owner+group
chown -R user dir     # recursive owner

Users & Groups

whoami  id  groups             # who am I, my ids/groups
sudo useradd -m -s /bin/bash u  # create user with home
sudo passwd u                   # set password
sudo usermod -aG docker u       # add to group (append)
su - u                          # switch user
sudo -i                         # root login shell

Processes & Services

Processes

ps aux              # all processes
ps -ef | grep name  # find a process
top   htop          # live monitors
kill 1234           # SIGTERM (graceful)
kill -9 1234        # SIGKILL (force)
pkill -f "pattern"  # kill by command line

systemd

systemctl status nginx        # state
systemctl start|stop|restart nginx
systemctl reload nginx        # reload config, no restart
systemctl enable --now nginx  # start + on boot
journalctl -u nginx -f        # follow logs
journalctl -p err -b          # errors this boot

Packages

# Debian / Ubuntu
sudo apt update && sudo apt install pkg
sudo apt upgrade   sudo apt remove pkg
apt search term

# Fedora / RHEL / Rocky
sudo dnf install pkg   sudo dnf upgrade
sudo dnf remove pkg    dnf search term

Networking

ip addr             # interfaces + IPs
ip route            # routing table
ss -tulpn           # listening sockets + PIDs
ping -c4 1.1.1.1    # connectivity
dig host +short     # DNS lookup
nc -zv host 5432    # is TCP port open
curl -sSL URL       # fetch (silent, follow)
curl -X POST -d @body.json -H 'Content-Type: application/json' URL

Text Processing

grep -rn "ERROR" dir/       # recursive + line nums
grep -i -A3 term file       # ignore case, 3 lines after
sed 's/a/b/g' file          # substitute all
sed -i '/^#/d' file         # delete comment lines
awk '{print $1,$9}' log     # columns
awk -F: '$3>=1000' /etc/passwd
find . -name "*.log" -mtime +7 -delete
find . -type f -size +100M  # big files

Pipes & Redirection

a | b               # pipe stdout -> stdin
cmd > f   cmd >> f   # write / append
cmd 2> err          # stderr to file
cmd > f 2>&1        # merge stderr into stdout
cmd > /dev/null 2>&1 # discard everything
sort f | uniq -c | sort -rn  # frequency count

Env & SSH

Environment

echo $PATH          # search path
export KEY=value    # set for children
printenv | sort     # list all
KEY=v cmd           # set for one command

SSH & Transfer

ssh-keygen -t ed25519       # new key
ssh-copy-id user@host       # install key
ssh user@host               # connect
scp file user@host:/path/   # copy over ssh
rsync -avz ./dir/ user@host:/dst/  # sync

Section navigation