🔍

📦 Package Management (apt / dpkg)

Debian uses the Advanced Package Tool (apt) and dpkg for managing software packages. These are the most essential commands every Debian user should know.

Basic apt Commands

Command Description
sudo apt updateUpdate package lists from repositories
sudo apt upgradeUpgrade all installed packages to latest versions
sudo apt full-upgradeUpgrade packages, handling dependency changes (may remove packages)
sudo apt install <package>Install a new package
sudo apt remove <package>Remove a package (keeps config files)
sudo apt purge <package>Remove a package and its configuration files
sudo apt autoremoveRemove unused dependency packages
sudo apt autocleanClean up old package files from the cache
apt search <term>Search for packages by name or description
apt show <package>Show detailed information about a package
apt list --installedList all installed packages
apt list --upgradableList packages that can be upgraded
apt policy <package>Show version policy and repository priority
bash
# Full system update routine
$ sudo apt update
$ sudo apt full-upgrade -y
$ sudo apt autoremove --purge -y
$ sudo apt autoclean

dpkg Commands

Command Description
dpkg -i <file.deb>Install a .deb package file
dpkg -r <package>Remove a package
dpkg -P <package>Purge a package (remove + configs)
dpkg -lList all installed packages
dpkg -l | grep <term>Search installed packages
dpkg -s <package>Show package status and info
dpkg -L <package>List files installed by a package
dpkg -S <file>Find which package owns a file
dpkg --configure -aFix broken package configurations
⚠️

apt vs dpkg

Always prefer apt over dpkg for installing packages, as apt automatically resolves dependencies. Use dpkg for installing local .deb files and querying package information.

⚙️ System Administration

System Information

Command Description
uname -aDisplay kernel and system information
cat /etc/os-releaseShow OS version and codename
hostnamectlDisplay and control system hostname
lsb_release -aShow LSB and distribution information
inxi -FxzDetailed hardware and system info (install with apt)
neofetchPretty system information display (install with apt)
uptimeShow how long the system has been running
whoamiDisplay current username
dateDisplay current date and time

Systemd Service Management

bash
# Start a service
$ sudo systemctl start nginx

# Stop a service
$ sudo systemctl stop nginx

# Restart a service
$ sudo systemctl restart nginx

# Enable service to start at boot
$ sudo systemctl enable nginx

# Disable service from starting at boot
$ sudo systemctl disable nginx

# Check service status
$ systemctl status nginx

# List all running services
$ systemctl list-units --type=service --state=running

# View system logs
$ journalctl -xe

# View logs for a specific service
$ journalctl -u nginx -f

Boot & Shutdown

Command Description
sudo shutdown -h nowShut down the system immediately
sudo shutdown -r nowReboot the system immediately
sudo shutdown -h +30Shut down in 30 minutes
sudo rebootReboot the system
sudo poweroffPower off the system

📁 Files & Disk Management

File Operations

Command Description
ls -laList all files with details (hidden included)
cd /pathChange directory
mkdir -p dir1/dir2/dir3Create directories (including parents)
cp -r src/ dest/Copy directory recursively
mv file1 file2Move or rename a file
rm -rf directory/Remove directory recursively (⚠️ dangerous)
find / -name "file.txt"Search for files by name
locate file.txtQuick file search (uses updatedb database)
cat file.txtDisplay file contents
less file.txtView file contents page by page
head -n 20 file.txtShow first 20 lines of a file
tail -f /var/log/syslogFollow log file in real-time
grep "pattern" file.txtSearch for text pattern in file
grep -r "pattern" /path/Recursively search for pattern in directory
wc -l file.txtCount lines in a file
diff file1 file2Compare two files

Disk & Storage

bash
# Check disk space usage
$ df -h

# Check directory sizes
$ du -sh /*

# Find large files (over 100MB)
$ find / -type f -size +100M

# List block devices
$ lsblk

# Check file system type
$ sudo blkid

# Check inode usage
$ df -i

🌐 Network Commands

Command Description
ip addr showShow IP addresses on all interfaces
ip link showShow network interfaces
ip route showShow routing table
ip link set eth0 upEnable network interface
ping -c 4 debian.orgPing a host 4 times
curl -s ifconfig.meGet public IP address
dig debian.orgQuery DNS records
nslookup debian.orgLookup DNS information
ss -tulnShow listening ports (modern netstat replacement)
ss -sShow socket statistics summary
traceroute debian.orgTrace network route to host
wget https://url/fileDownload a file from the web
curl -O https://url/fileDownload a file preserving name

Firewall (UFW)

bash
# Install UFW (if not installed)
$ sudo apt install ufw

# Enable firewall
$ sudo ufw enable

# Check status
$ sudo ufw status verbose

# Allow SSH
$ sudo ufw allow 22/tcp

# Allow HTTP and HTTPS
$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp

# Deny a specific IP
$ sudo ufw deny from 192.168.1.100

# Delete a rule
$ sudo ufw delete allow 80

👤 Users, Permissions & Processes

User Management

Command Description
sudo adduser usernameCreate a new user (interactive)
sudo deluser usernameDelete a user
sudo usermod -aG sudo usernameAdd user to sudo group
sudo passwd usernameChange user password
id usernameShow user ID and groups
groups usernameShow groups a user belongs to
whoShow logged-in users
lastShow login history

File Permissions

bash
# Change permissions (read=4, write=2, execute=1)
$ chmod 755 script.sh      # rwxr-xr-x
$ chmod 644 file.txt     # rw-r--r--
$ chmod 600 secret.key   # rw-------

# Change ownership
$ sudo chown user:group file

# Change ownership recursively
$ sudo chown -R user:group directory/

Process Management

Command Description
ps auxList all running processes
topInteractive process viewer
htopEnhanced interactive process viewer (install with apt)
kill PIDSend SIGTERM to a process
kill -9 PIDForce kill a process (SIGKILL)
pkill processnameKill process by name
pgrep processnameFind PID by process name
lsof -i :80Show which process uses port 80
free -hShow memory usage in human-readable format
vmstat 1Virtual memory statistics (update every 1s)

🔧 Shell & Text Processing

bash
# Text processing with grep
$ grep -i "error" /var/log/syslog          # Case-insensitive search
$ grep -r "TODO" /home/user/project/    # Recursive search
$ grep -c "pattern" file                 # Count matching lines

# Text processing with sed
$ sed -i s/old/new/g file.txt             # Find and replace in-place
$ sed -n '5,10p' file.txt                  # Print lines 5-10

# Text processing with awk
$ awk '{print $1}' file.txt               # Print first column
$ awk '-F:' '{print $1}' /etc/passwd      # Print usernames from passwd

# Compression
$ tar -czf archive.tar.gz directory/      # Create gzip archive
$ tar -xzf archive.tar.gz                  # Extract gzip archive
$ tar -tjf archive.tar.bz2                 # List bzip2 archive contents

# Pipes and redirection
$ cat file | grep "pattern" | sort | uniq
$ command > output.txt                     # Redirect output to file
$ command 2>&1 > log.txt                    # Redirect stdout and stderr