System Info
| Command | Description |
uname -a | Full system information (kernel, hostname, architecture) |
hostnamectl | Hostname and OS details |
lsb_release -a | Distribution info (Ubuntu/Debian) |
cat /etc/os-release | OS release information |
uptime | System uptime and load averages |
free -h | Memory usage in human-readable format |
nproc | Number of available CPU cores |
lscpu | CPU architecture details |
date | Current date and time |
timedatectl | Timezone and NTP sync status |
File Management
| Command | Description |
ls -lah | List all files with details and human-readable sizes |
cd /path/to/dir | Change directory |
pwd | Print working directory |
mkdir -p dir/sub | Create nested directories |
cp -r src dest | Copy files/directories recursively |
mv old new | Move or rename files |
rm -rf dir | Remove directory and contents (use with caution) |
find / -name "*.log" | Find files by name pattern |
find / -mtime -7 | Find files modified in last 7 days |
tar -czf archive.tar.gz dir/ | Create gzip-compressed archive |
tar -xzf archive.tar.gz | Extract gzip archive |
ln -s target link | Create symbolic link |
du -sh * | Directory sizes in current folder |
wc -l file | Count 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
| Command | Description |
whoami | Current username |
id | User ID, group ID and groups |
adduser username | Create user interactively (Debian/Ubuntu) |
useradd -m -s /bin/bash user | Create user with home dir and shell |
usermod -aG sudo user | Add user to sudo group |
passwd user | Change user password |
userdel -r user | Delete user and home directory |
groups user | List groups for a user |
su - user | Switch to user with login shell |
visudo | Safely edit sudoers file |
Permissions
| Command | Description |
chmod 755 file | rwxr-xr-x (owner full, group/others read+exec) |
chmod 644 file | rw-r--r-- (owner read+write, others read) |
chmod +x script.sh | Add execute permission |
chmod -R 750 dir/ | Recursive permission change |
chown user:group file | Change 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)
| Command | Description |
apt update | Refresh package index |
apt upgrade | Upgrade installed packages |
apt full-upgrade | Upgrade with dependency changes |
apt install pkg | Install a package |
apt remove pkg | Remove a package (keep config) |
apt purge pkg | Remove package and config files |
apt autoremove | Remove unused dependencies |
apt search keyword | Search for packages |
apt show pkg | Package details |
dpkg -l | List all installed packages |
dpkg -L pkg | List files installed by a package |
Process Management
| Command | Description |
ps aux | List all running processes |
ps aux | grep name | Find process by name |
top | Interactive process viewer |
htop | Enhanced process viewer (install separately) |
kill PID | Graceful terminate (SIGTERM) |
kill -9 PID | Force kill (SIGKILL) |
killall name | Kill all processes by name |
pgrep -f pattern | Find PIDs by pattern |
nohup cmd & | Run command immune to hangups |
jobs | List background jobs |
bg / fg | Resume job in background / foreground |
Networking
| Command | Description |
ip a | Show all network interfaces and IPs |
ip r | Show routing table |
ss -tulnp | Show listening ports with process names |
ping -c 4 host | Ping with count limit |
traceroute host | Trace packet route |
dig domain | DNS lookup |
nslookup domain | Query DNS server |
curl -I url | Fetch HTTP headers only |
wget url | Download file |
netstat -tulnp | Network 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
| Command | Description |
systemctl start svc | Start a service |
systemctl stop svc | Stop a service |
systemctl restart svc | Restart a service |
systemctl reload svc | Reload config without restart |
systemctl status svc | Service status and recent logs |
systemctl enable svc | Enable on boot |
systemctl disable svc | Disable on boot |
systemctl list-units --type=service | List active services |
journalctl -u svc -f | Follow service logs |
journalctl -u svc --since "1 hour ago" | Recent logs for a service |
journalctl --disk-usage | Journal storage size |
Disk & Storage
| Command | Description |
df -h | Filesystem disk space usage |
du -sh /path | Size of a directory |
du -h --max-depth=1 | Sizes of subdirectories |
lsblk | List block devices |
fdisk -l | List disk partitions |
mount /dev/sdb1 /mnt | Mount a partition |
umount /mnt | Unmount |
blkid | Show UUIDs and filesystem types |
ncdu / | Interactive disk usage analyzer |
SSH
| Command | Description |
ssh user@host | Connect to remote server |
ssh -p 2222 user@host | Connect on custom port |
ssh-keygen -t ed25519 | Generate Ed25519 key pair |
ssh-copy-id user@host | Copy public key to server |
ssh -L 8080:localhost:80 user@host | Local port forwarding |
ssh -R 9090:localhost:3000 user@host | Remote port forwarding |
scp file user@host:/path | Copy file to remote server |
scp -r dir user@host:/path | Copy directory recursively |
rsync -avz src user@host:/dest | Efficient 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