CodeBrowser

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

CommandWhat it does
pwdShow the current folder
ls -lahList files with sizes, permissions and hidden files
cd /var/wwwGo to a folder
cd ~Go to your home folder
cd -Go back to the previous folder
tree -L 2Show the folder tree two levels deep
find . -name "*.log"Find files by name

Files

Working with files

CommandWhat it does
cat file.txtPrint a file
less file.txtScroll through a file (q to quit)
tail -f app.logFollow a file as it grows
cp -r src destCopy a file or folder
mv old newMove or rename
rm -r folderDelete a folder (no undo)
mkdir -p a/b/cCreate nested folders
grep -rn "text" .Search inside files

Permissions

Permissions and ownership

CommandWhat it does
chmod 644 fileOwner read/write, everyone else read
chmod 755 dirStandard folder and script permissions
chmod +x script.shMake a script executable
chown user:group fileChange owner and group
chown -R www-data: /var/wwwChange owner of a folder and its contents

Not sure what a number means? Work it out with our Chmod Calculator.

Users

Users and sudo

CommandWhat it does
whoamiShow your username
sudo -iOpen a root shell
adduser deployCreate a user
usermod -aG sudo deployGive a user sudo rights
passwdChange your password
whoSee who is logged in

Processes

Processes and resources

CommandWhat it does
htopLive view of CPU, memory and processes
ps aux | grep nginxFind a running process
kill 1234Stop a process by its ID
free -hShow memory use
uptimeShow load average and uptime
nprocNumber of CPU cores

Disks

Disk space

CommandWhat it does
df -hFree space on each disk
du -sh *Size of each item in the current folder
du -h --max-depth=1 / | sort -hFind the biggest top-level folders
ncdu /Interactive disk usage explorer
lsblkList disks and partitions

Services

Services with systemctl

CommandWhat it does
systemctl status nginxIs a service running?
sudo systemctl restart nginxRestart a service
sudo systemctl reload nginxReload its config without stopping
sudo systemctl enable --now nginxStart now and at every boot
systemctl list-units --failedShow failed services

Logs

Reading logs

CommandWhat it does
journalctl -u nginx -n 50Last 50 log lines for a service
journalctl -fFollow all system logs live
journalctl --since "1 hour ago"Logs from the last hour
dmesg | tailRecent kernel messages
tail -f /var/log/nginx/error.logFollow a log file

Packages

Installing software (apt)

CommandWhat it does
sudo apt updateRefresh the package list
sudo apt upgrade -yInstall all updates
sudo apt install nginxInstall a package
sudo apt remove nginxRemove a package
apt search keywordSearch for packages
sudo apt autoremoveRemove unused packages

Networking

Network and firewall

CommandWhat it does
ip aShow IP addresses
sudo ss -tlnpWhich programs listen on which ports
curl -I https://example.comCheck a website’s response headers
ping -c 4 example.comTest connectivity
sudo ufw statusShow firewall rules
sudo ufw allow 443/tcpOpen a port

SSH

SSH and file transfer

CommandWhat it does
ssh user@serverConnect to a server
ssh-keygen -t ed25519Create an SSH key
ssh-copy-id user@serverCopy 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

CommandWhat it does
tar -czf backup.tar.gz dir/Create a compressed archive
tar -xzf backup.tar.gzExtract a .tar.gz archive
zip -r site.zip dir/Create a zip file
unzip site.zipExtract a zip file
wget https://example.com/fileDownload 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.

Best overall

DigitalOcean

Simple cloud servers with great docs. Add your SSH key when you create a Droplet.

From about $4/month

View DigitalOcean deals
Most RAM for the money

Hostinger

4 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 VPS
Best budget

RackNerd

Yearly KVM VPS deals for about the price of one month elsewhere. Great for learning.

From about $11/year on promo

View RackNerd deals

Prices 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.