Commands Guide
A comprehensive reference of essential Debian commands for package management, system administration, and daily operations.
📦 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 update | Update package lists from repositories |
sudo apt upgrade | Upgrade all installed packages to latest versions |
sudo apt full-upgrade | Upgrade 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 autoremove | Remove unused dependency packages |
sudo apt autoclean | Clean 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 --installed | List all installed packages |
apt list --upgradable | List 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 -l | List 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 -a | Fix 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 -a | Display kernel and system information |
cat /etc/os-release | Show OS version and codename |
hostnamectl | Display and control system hostname |
lsb_release -a | Show LSB and distribution information |
inxi -Fxz | Detailed hardware and system info (install with apt) |
neofetch | Pretty system information display (install with apt) |
uptime | Show how long the system has been running |
whoami | Display current username |
date | Display 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 now | Shut down the system immediately |
sudo shutdown -r now | Reboot the system immediately |
sudo shutdown -h +30 | Shut down in 30 minutes |
sudo reboot | Reboot the system |
sudo poweroff | Power off the system |
📁 Files & Disk Management
File Operations
| Command | Description |
|---|---|
ls -la | List all files with details (hidden included) |
cd /path | Change directory |
mkdir -p dir1/dir2/dir3 | Create directories (including parents) |
cp -r src/ dest/ | Copy directory recursively |
mv file1 file2 | Move or rename a file |
rm -rf directory/ | Remove directory recursively (⚠️ dangerous) |
find / -name "file.txt" | Search for files by name |
locate file.txt | Quick file search (uses updatedb database) |
cat file.txt | Display file contents |
less file.txt | View file contents page by page |
head -n 20 file.txt | Show first 20 lines of a file |
tail -f /var/log/syslog | Follow log file in real-time |
grep "pattern" file.txt | Search for text pattern in file |
grep -r "pattern" /path/ | Recursively search for pattern in directory |
wc -l file.txt | Count lines in a file |
diff file1 file2 | Compare 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 show | Show IP addresses on all interfaces |
ip link show | Show network interfaces |
ip route show | Show routing table |
ip link set eth0 up | Enable network interface |
ping -c 4 debian.org | Ping a host 4 times |
curl -s ifconfig.me | Get public IP address |
dig debian.org | Query DNS records |
nslookup debian.org | Lookup DNS information |
ss -tuln | Show listening ports (modern netstat replacement) |
ss -s | Show socket statistics summary |
traceroute debian.org | Trace network route to host |
wget https://url/file | Download a file from the web |
curl -O https://url/file | Download 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 username | Create a new user (interactive) |
sudo deluser username | Delete a user |
sudo usermod -aG sudo username | Add user to sudo group |
sudo passwd username | Change user password |
id username | Show user ID and groups |
groups username | Show groups a user belongs to |
who | Show logged-in users |
last | Show 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 aux | List all running processes |
top | Interactive process viewer |
htop | Enhanced interactive process viewer (install with apt) |
kill PID | Send SIGTERM to a process |
kill -9 PID | Force kill a process (SIGKILL) |
pkill processname | Kill process by name |
pgrep processname | Find PID by process name |
lsof -i :80 | Show which process uses port 80 |
free -h | Show memory usage in human-readable format |
vmstat 1 | Virtual 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