Back to blog

Linux Commands for VPS Beginners: 33 Commands You Will Actually Use

IM Host EditorialOctober 10, 20268 min read
Linux Commands for VPS Beginners: 33 Commands You Will Actually Use

You do not need hundreds of Linux commands to run a VPS. About thirty cover nearly all daily work: moving around the file system, editing files, fixing permissions, checking CPU, memory and disk, restarting services, reading logs, testing the network and installing packages. This guide groups them by task, with one practical example each, then shows the five-minute routine to follow when someone says "the site is slow".

Examples are for Ubuntu and Debian. Commands that change the system need sudo when you are logged in as a normal user, which is how you should work. If you have not set that up yet, start with our guide to securing a Linux VPS with SSH keys, UFW and fail2ban.

Navigate and manage files

  • pwd prints the directory you are in. Run it before any delete.

  • ls -lah lists files with sizes, owners and hidden files such as .env and .htaccess.

  • cd changes directory. cd /var/www goes to an absolute path, cd .. goes up, cd - returns to the previous one.

  • mkdir -p creates a directory and any missing parents: mkdir -p /var/www/example.com/public.

  • cp -a copies while keeping permissions and timestamps. Make a copy before editing a config: sudo cp -a /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak.

  • mv moves or renames: mv old-name.php new-name.php.

  • rm deletes with no recycle bin. rm -r dir deletes a directory. Prefer rm -ri when unsure; it asks before each file.

  • nano is the easiest editor for beginners. Save with Ctrl+O, exit with Ctrl+X.

  • less reads long files page by page: less /var/log/syslog. Press / to search, q to quit.

  • tail -f follows a log live while you reproduce a problem: sudo tail -f /var/log/nginx/error.log.

  • grep finds text. grep -Rn "DB_HOST" /var/www/example.com shows every file and line that mentions it.

  • find finds files by name, size or age. Large files: sudo find / -xdev -type f -size +500M.

Permissions and ownership

Most "403 Forbidden" and "permission denied" errors come down to these three:

  • sudo runs one command as root: sudo systemctl restart nginx.

  • chown changes the owner. Web files usually belong to the web server user: sudo chown -R www-data:www-data /var/www/example.com.

  • chmod changes permissions. The safe default for websites is 755 for directories and 644 for files:

sudo find /var/www/example.com -type d -exec chmod 755 {} \;
sudo find /var/www/example.com -type f -exec chmod 644 {} \;

Files with secrets, such as .env or wp-config.php, can go stricter with 640 or 600 as long as the app user can still read them.

Processes and resources

  • uptime shows load average for 1, 5 and 15 minutes. As a rule of thumb, a load that stays above your number of vCPUs means work is queuing.

  • top shows live CPU and memory per process. On the %Cpu(s) line, wa is time waiting for disk and st is CPU steal from the host. Our explainer on KVM virtualization and CPU steal covers what a high st means.

  • htop is a friendlier top with colours and sorting. Install with sudo apt install htop if missing.

  • free -h shows memory. Read the available column, not free: Linux uses spare RAM for cache, and that is good.

  • df -h shows free disk space per file system. df -i shows inodes; a disk can be "full" with free gigabytes if you run out of inodes.

  • du -sh shows what uses space: sudo du -sh /var/* | sort -h lists the biggest directories last.

  • ps lists processes. Top memory users: ps aux --sort=-%mem | head -n 10.

  • kill stops a process by its PID: kill 12345. Use kill -9 only if it ignores the normal signal. For services, use systemctl instead.

Services and logs

  • systemctl manages services:

sudo systemctl status nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
sudo systemctl enable --now nginx
systemctl list-units --type=service --state=failed

reload applies config without dropping connections where the service supports it. Always test nginx config first with sudo nginx -t.

  • journalctl reads the systemd journal. The last hour of one service: sudo journalctl -u nginx --since "1 hour ago". Follow live with -f. Errors since the last boot: sudo journalctl -p err -b.

Network

  • ip a shows your IPv4 and IPv6 addresses per interface.

  • ss -tulpn shows which ports are listening and which program owns each one (run with sudo to see program names).

  • curl tests HTTP from the server itself: curl -I https://example.com shows status code and headers. Replace example.com with your domain.

  • ping checks basic reachability and latency: ping -c 5 example.com.

  • dig checks DNS: dig +short A example.com tells you which IP the domain points to. Install with sudo apt install dnsutils if missing.

Packages

  • apt is the package manager on Ubuntu and Debian:

sudo apt update
apt list --upgradable
sudo apt upgrade
sudo apt install nginx
sudo apt remove --purge package-name
sudo apt autoremove

update refreshes the package list; upgrade installs the updates. RHEL-family systems such as AlmaLinux use dnf instead. Our comparison of Linux distributions for a VPS explains those differences.

Archives and file transfer

  • tar packs and unpacks archives:

tar -czf site-2026-10-10.tar.gz /var/www/example.com
tar -tzf site-2026-10-10.tar.gz | head
tar -xzf site-2026-10-10.tar.gz -C /tmp/restore

The middle line lists contents without extracting, a quick check that the archive is not empty.

  • rsync copies efficiently between servers and resumes where it stopped: rsync -avz /var/www/example.com/ [email protected]:/var/www/example.com/. The trailing slashes mean "the contents of".

Dangerous commands and habits

  • rm -rf with a variable or wildcard. rm -rf $DIR/* with an empty $DIR becomes rm -rf /*. Check with echo first, use quotes, and never run delete commands you copied without reading.

  • chmod -R 777. It "fixes" permission errors by letting any process write anywhere in your site, including a compromised plugin. Fix the owner with chown instead.

  • chown -R on the wrong path. Running it on / or /etc can break sudo and SSH. Double-check the path.

  • dd or mkfs on the wrong disk. Confirm the device name with lsblk before touching a disk.

  • Piping internet scripts to bash. curl ... | sudo bash runs code you have not read as root. Download, read, then run.

  • Deleting a log that is still open. The disk space is not freed until the process restarts. Empty it instead: sudo truncate -s 0 /var/log/big.log.

  • Restarting SSH or enabling a firewall from your only session. Keep a second session open.

A five-minute routine for "the site is slow"

  1. Load: uptime and nproc. Load well above the vCPU count means CPU pressure.

  2. Who uses CPU: top, press P to sort by CPU. Note wa (disk) and st (steal).

  3. Memory: free -h. Low available and growing swap use mean you are short on RAM.

  4. Disk: df -h and df -i. A full disk breaks databases and sessions in strange ways.

  5. Errors: sudo tail -n 50 /var/log/nginx/error.log and sudo journalctl -p err --since "30 min ago".

  6. Services: systemctl status php8.3-fpm on Ubuntu 24.04 (php8.1-fpm on 22.04), or your app service and database.

  7. Time to first byte from the server itself:

curl -o /dev/null -s -w 'connect=%{time_connect} ttfb=%{time_starttransfer} total=%{time_total}\n' https://example.com

If TTFB is fast from the server but slow for visitors, look at network distance and front-end weight, not the server. For audiences in Egypt, our guide to VPS hosting for Egypt discusses location choices.

Frequently asked questions

What are the most important Linux commands for a server?

For daily VPS work: ls, cd, nano, tail -f, grep, systemctl, journalctl, df -h, free -h, top, ss -tulpn and apt. Learn those first and add the rest as you need them.

How do I check CPU and RAM usage on a Linux VPS?

Use top or htop for live CPU and memory per process, free -h for total memory, and uptime for load average compared with your vCPU count from nproc.

How do I find what is filling my disk?

Run df -h to see which file system is full, then sudo du -sh /var/* | sort -h and drill down. Logs, old backups and caches are the usual causes. Also check df -i for inodes.

Is it safe to practise commands on a production server?

Read-only commands such as ls, df, top and journalctl are safe. Practise anything that deletes, moves or changes permissions on a test server or a copy first.

The best way to learn these is on a server of your own. An IM HOST Linux VPS gives you full root access on KVM with Ubuntu, Debian, CentOS Stream or AlmaLinux, and if a command does something you did not expect, our engineers answer 24/7.

More from our blog

Discover more practical guides and product insights from the IM Host team.

View all articles