Linux Quick Reference

Essential commands for system administration, files, users, networking and more.

System Info

CommandDescription
uname -aFull system information (kernel, hostname, architecture)
hostnamectlHostname and OS details
lsb_release -aDistribution info (Ubuntu/Debian)
cat /etc/os-releaseOS release information
uptimeSystem uptime and load averages
free -hMemory usage in human-readable format
nprocNumber of available CPU cores
lscpuCPU architecture details
dateCurrent date and time
timedatectlTimezone and NTP sync status

File Management

CommandDescription
ls -lahList all files with details and human-readable sizes
cd /path/to/dirChange directory
pwdPrint working directory
mkdir -p dir/subCreate nested directories
cp -r src destCopy files/directories recursively
mv old newMove or rename files
rm -rf dirRemove directory and contents (use with caution)
find / -name "*.log"Find files by name pattern
find / -mtime -7Find files modified in last 7 days
tar -czf archive.tar.gz dir/Create gzip-compressed archive
tar -xzf archive.tar.gzExtract gzip archive
ln -s target linkCreate symbolic link
du -sh *Directory sizes in current folder
wc -l fileCount lines in a file

Searching file contents

grep -r "pattern" /path          # Recursive search
grep -rn "pattern" .              # With line numbers
grep -i "pattern" file            # Case-insensitive
grep -v "exclude" file            # Invert match
grep -E "regex|pattern" file      # Extended regex

User Management

CommandDescription
whoamiCurrent username
idUser ID, group ID and groups
adduser usernameCreate user interactively (Debian/Ubuntu)
useradd -m -s /bin/bash userCreate user with home dir and shell
usermod -aG sudo userAdd user to sudo group
passwd userChange user password
userdel -r userDelete user and home directory
groups userList groups for a user
su - userSwitch to user with login shell
visudoSafely edit sudoers file

Permissions

CommandDescription
chmod 755 filerwxr-xr-x (owner full, group/others read+exec)
chmod 644 filerw-r--r-- (owner read+write, others read)
chmod +x script.shAdd execute permission
chmod -R 750 dir/Recursive permission change
chown user:group fileChange file owner and group
chown -R user:group dir/Recursive ownership change

Permission reference

# Numeric: read(4) + write(2) + execute(1)
# 7 = rwx    5 = r-x    4 = r--
# 6 = rw-    3 = -wx    0 = ---

# Common patterns:
# 755 — directories, scripts       (rwxr-xr-x)
# 644 — regular files              (rw-r--r--)
# 600 — private files, SSH keys    (rw-------)
# 700 — private directories        (rwx------)

Package Management (apt)

CommandDescription
apt updateRefresh package index
apt upgradeUpgrade installed packages
apt full-upgradeUpgrade with dependency changes
apt install pkgInstall a package
apt remove pkgRemove a package (keep config)
apt purge pkgRemove package and config files
apt autoremoveRemove unused dependencies
apt search keywordSearch for packages
apt show pkgPackage details
dpkg -lList all installed packages
dpkg -L pkgList files installed by a package

Process Management

CommandDescription
ps auxList all running processes
ps aux | grep nameFind process by name
topInteractive process viewer
htopEnhanced process viewer (install separately)
kill PIDGraceful terminate (SIGTERM)
kill -9 PIDForce kill (SIGKILL)
killall nameKill all processes by name
pgrep -f patternFind PIDs by pattern
nohup cmd &Run command immune to hangups
jobsList background jobs
bg / fgResume job in background / foreground

Networking

CommandDescription
ip aShow all network interfaces and IPs
ip rShow routing table
ss -tulnpShow listening ports with process names
ping -c 4 hostPing with count limit
traceroute hostTrace packet route
dig domainDNS lookup
nslookup domainQuery DNS server
curl -I urlFetch HTTP headers only
wget urlDownload file
netstat -tulnpNetwork connections (legacy, use ss)

Firewall (UFW)

ufw status                     # Check firewall status
ufw enable                     # Enable firewall
ufw allow 22/tcp               # Allow SSH
ufw allow 80,443/tcp           # Allow HTTP + HTTPS
ufw deny from 10.0.0.5         # Block specific IP
ufw delete allow 80/tcp        # Remove rule
ufw reset                      # Reset all rules

Systemd Services

CommandDescription
systemctl start svcStart a service
systemctl stop svcStop a service
systemctl restart svcRestart a service
systemctl reload svcReload config without restart
systemctl status svcService status and recent logs
systemctl enable svcEnable on boot
systemctl disable svcDisable on boot
systemctl list-units --type=serviceList active services
journalctl -u svc -fFollow service logs
journalctl -u svc --since "1 hour ago"Recent logs for a service
journalctl --disk-usageJournal storage size

Disk & Storage

CommandDescription
df -hFilesystem disk space usage
du -sh /pathSize of a directory
du -h --max-depth=1Sizes of subdirectories
lsblkList block devices
fdisk -lList disk partitions
mount /dev/sdb1 /mntMount a partition
umount /mntUnmount
blkidShow UUIDs and filesystem types
ncdu /Interactive disk usage analyzer

SSH

CommandDescription
ssh user@hostConnect to remote server
ssh -p 2222 user@hostConnect on custom port
ssh-keygen -t ed25519Generate Ed25519 key pair
ssh-copy-id user@hostCopy public key to server
ssh -L 8080:localhost:80 user@hostLocal port forwarding
ssh -R 9090:localhost:3000 user@hostRemote port forwarding
scp file user@host:/pathCopy file to remote server
scp -r dir user@host:/pathCopy directory recursively
rsync -avz src user@host:/destEfficient sync with compression

SSH config (~/.ssh/config)

Host myserver
    HostName 192.168.1.100
    User deploy
    Port 2222
    IdentityFile ~/.ssh/id_ed25519
    ServerAliveInterval 60
    ServerAliveCountMax 3