We earn commissions when you shop through the links below. Learn more
Linux Commands Cheat Sheet for Servers
The Linux commands you actually use on a server, grouped by task: files, permissions, processes, networking, disks, packages, services, logs and SSH. Bookmark it and keep it open in a tab.
Ubuntu & Debian100+ commandsServer-focusedCopy-ready
Navigation
Moving around
| Command | What it does |
|---|---|
pwd | Show the current folder |
ls -lah | List files with sizes, permissions and hidden files |
cd /var/www | Go to a folder |
cd ~ | Go to your home folder |
cd - | Go back to the previous folder |
tree -L 2 | Show the folder tree two levels deep |
find . -name "*.log" | Find files by name |
Files
Working with files
| Command | What it does |
|---|---|
cat file.txt | Print a file |
less file.txt | Scroll through a file (q to quit) |
tail -f app.log | Follow a file as it grows |
cp -r src dest | Copy a file or folder |
mv old new | Move or rename |
rm -r folder | Delete a folder (no undo) |
mkdir -p a/b/c | Create nested folders |
grep -rn "text" . | Search inside files |
Permissions
Permissions and ownership
| Command | What it does |
|---|---|
chmod 644 file | Owner read/write, everyone else read |
chmod 755 dir | Standard folder and script permissions |
chmod +x script.sh | Make a script executable |
chown user:group file | Change owner and group |
chown -R www-data: /var/www | Change owner of a folder and its contents |
Not sure what a number means? Work it out with our Chmod Calculator.
Users
Users and sudo
| Command | What it does |
|---|---|
whoami | Show your username |
sudo -i | Open a root shell |
adduser deploy | Create a user |
usermod -aG sudo deploy | Give a user sudo rights |
passwd | Change your password |
who | See who is logged in |
Processes
Processes and resources
| Command | What it does |
|---|---|
htop | Live view of CPU, memory and processes |
ps aux | grep nginx | Find a running process |
kill 1234 | Stop a process by its ID |
free -h | Show memory use |
uptime | Show load average and uptime |
nproc | Number of CPU cores |
Disks
Disk space
| Command | What it does |
|---|---|
df -h | Free space on each disk |
du -sh * | Size of each item in the current folder |
du -h --max-depth=1 / | sort -h | Find the biggest top-level folders |
ncdu / | Interactive disk usage explorer |
lsblk | List disks and partitions |
Services
Services with systemctl
| Command | What it does |
|---|---|
systemctl status nginx | Is a service running? |
sudo systemctl restart nginx | Restart a service |
sudo systemctl reload nginx | Reload its config without stopping |
sudo systemctl enable --now nginx | Start now and at every boot |
systemctl list-units --failed | Show failed services |
Logs
Reading logs
| Command | What it does |
|---|---|
journalctl -u nginx -n 50 | Last 50 log lines for a service |
journalctl -f | Follow all system logs live |
journalctl --since "1 hour ago" | Logs from the last hour |
dmesg | tail | Recent kernel messages |
tail -f /var/log/nginx/error.log | Follow a log file |
Packages
Installing software (apt)
| Command | What it does |
|---|---|
sudo apt update | Refresh the package list |
sudo apt upgrade -y | Install all updates |
sudo apt install nginx | Install a package |
sudo apt remove nginx | Remove a package |
apt search keyword | Search for packages |
sudo apt autoremove | Remove unused packages |
Networking
Network and firewall
| Command | What it does |
|---|---|
ip a | Show IP addresses |
sudo ss -tlnp | Which programs listen on which ports |
curl -I https://example.com | Check a website’s response headers |
ping -c 4 example.com | Test connectivity |
sudo ufw status | Show firewall rules |
sudo ufw allow 443/tcp | Open a port |
SSH
SSH and file transfer
| Command | What it does |
|---|---|
ssh user@server | Connect to a server |
ssh-keygen -t ed25519 | Create an SSH key |
ssh-copy-id user@server | Copy your key to a server |
scp file user@server:~/ | Copy a file to a server |
rsync -avz dir/ user@server:dir/ | Sync a folder to a server |
More in our step-by-step guide on how to SSH into a server.
Archives
Compressing and extracting
| Command | What it does |
|---|---|
tar -czf backup.tar.gz dir/ | Create a compressed archive |
tar -xzf backup.tar.gz | Extract a .tar.gz archive |
zip -r site.zip dir/ | Create a zip file |
unzip site.zip | Extract a zip file |
wget https://example.com/file | Download a file |
Need a server?
Practice on a server of your own
The best way to learn these commands is on a cheap VPS you can rebuild any time. All of these give you full root access.
Simple cloud servers with great docs. Add your SSH key when you create a Droplet.
From about $4/month
View DigitalOcean deals4 GB of RAM and NVMe storage on the entry VPS plan, with an easy control panel.
About $5.19/month on a 24-month term with our extra 20% off
Get 20% off Hostinger VPSYearly KVM VPS deals for about the price of one month elsewhere. Great for learning.
From about $11/year on promo
View RackNerd dealsPrices are approximate. Compare all VPS hosts, including Vultr and ShockHosting.
FAQ
Linux command questions, answered
What are the most important Linux commands to learn first?
Start with ls, cd, pwd, cat, less, cp, mv, rm, mkdir, sudo, apt, systemctl and journalctl. Those cover most everyday server work.
How do I get help for a command?
Run man followed by the command name, for example man rsync, or add –help to most commands for a shorter summary.
Are these commands the same on every Linux?
Most are. The package commands here are for Ubuntu and Debian; Red Hat-based systems such as Rocky Linux and AlmaLinux use dnf instead of apt.
How do I undo rm?
You cannot. rm deletes files immediately with no recycle bin, so double-check paths and keep backups or snapshots of important servers.
What is the difference between sudo and root?
root is the all-powerful admin account. sudo lets a normal user run a single command as root, which is safer and leaves a record of who did what.
Where can I practice Linux commands safely?
On a cheap VPS you can rebuild at any time, or in a virtual machine on your own computer. Mistakes there cost nothing.