Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

Best Linux Commands for Ubuntu Users

By Kokil Thapa | Last reviewed: September 2026

The best Linux commands for Ubuntu users are not a random cheat sheet. They are the tools you reach for when a Laravel app works locally but fails after deploy, when disk space vanishes overnight, or when PHP-FPM stops answering Nginx. I run Ubuntu 22.04 and 24.04 on production servers daily. This guide ranks commands by what actually saves time on real web stacks. If you are new to the shell, pair this with our Ubuntu server setup guide first.

What are the best Linux commands for Ubuntu users on production web servers?

Production Ubuntu boxes for PHP and Laravel rarely need exotic utilities. You need fast answers to five questions: where am I, what changed, who owns it, what is running, and what broke. The commands below map directly to those questions.

On sister sites I maintain with Deployer 7 and GitLab CI, the same command set appears in every incident. A stale cron path, wrong PHP binary, or full /var/log partition surfaces through disk, process, and log commands—not through GUI tools.

Ubuntu Command MapFilesls find chmodPackagesapt dpkgServicessystemctlNetworkss ufw curlLogsjournalctl tailDaily workflowcheck disk, service, logs, deploy
Best Linux commands for Ubuntu users grouped by files, packages, services, network, and logs

Ranked by daily impact

  1. Navigation and inspection: pwd, cd, ls -lah, tree (install if missing), less, head, tail
  2. Search and edit: find, grep -R, rg (ripgrep), nano or vim
  3. Ownership and permissions: chown, chmod, stat, id, groups
  4. Processes and resources: ps, top, htop, free -h, df -h, du -sh
  5. Services: systemctl, journalctl — see our systemd service management guide
  6. Networking: ip, ss, curl, dig, ufw
  7. Packages: apt, dpkg, snap where relevant

This order reflects incident frequency, not alphabetical neatness. Disk and permission issues beat package bugs on most Laravel hosts I touch.

Which file and directory commands should every Ubuntu user memorize?

File commands are the foundation. A wrong chmod on storage/ breaks uploads. A misplaced chown leaves Nginx unable to read a release symlink. Learn these until they are muscle memory.

# Where am I? What is here?
pwd
cd /var/www/current
ls -lah

# Human-readable sizes, newest first
ls -lhtr storage/logs/

# Follow a Laravel log in real time
tail -f storage/logs/laravel.log

ls -lah shows hidden dotfiles, sizes, and permissions in one view. That matters when debugging .env visibility or stale .htaccess files on Apache setups.

# Find large log files older than 14 days
find /var/log -type f -name "*.log" -mtime +14 -ls

# Find world-writable files under a web root (security audit)
find /var/www -type f -perm -002 2>/dev/null

# Search config for a directive
grep -R "upload_max_filesize" /etc/php/8.4/fpm/

find is slower than locate but always current. After package upgrades, I use find to confirm which PHP-FPM pool files exist under /etc/php/. Our Ubuntu file permissions guide explains the numeric modes behind chmod.

Permission Fix Flow500 errorstat pathcheck ownerls -lasee modefix ownerchown/chmodLaravel deploy patternwww-data owns storage bootstrap/cacheDirectories 755files 644 typicalstorage 775group www-data
chmod and chown workflow when Laravel or Apache returns permission errors on Ubuntu

Copy, move, and archive

# Safe copy with preserve attributes
cp -a source/ destination/

# Move release artifacts
mv release-20260910 /var/www/releases/

# Tar backup before schema change
tar -czf ~/backup-$(date +%F).tar.gz /var/www/current/storage

cp -a preserves timestamps and symlinks. That matters when rsync or Deployer expects intact symlinked current releases. For scheduled dumps, see Ubuntu server backup strategies.

Permissions in practice

# Fix Laravel writable dirs after deploy
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

# Inspect numeric mode and owner
stat -c "%a %U:%G %n" storage/logs/laravel.log

Never run chmod 777 on production. It is a shortcut that creates audit and security debt. Fix the owner and group instead.

How do you monitor processes, disk, and memory on Ubuntu?

“The site is slow” usually means CPU, RAM, disk I/O, or a runaway queue worker. These commands tell you which one within seconds.

Process inspection

# Snapshot of top CPU consumers
ps aux --sort=-%cpu | head -15

# Interactive view (install: sudo apt install htop)
htop

# Find PHP-FPM workers
ps aux | grep php-fpm | grep -v grep

# Kill stuck queue worker by PID
kill -15 12847

Prefer kill -15 (SIGTERM) before kill -9. Laravel queue workers should drain gracefully when possible.

Disk and memory

# Filesystem usage — watch for 100% /var
df -h

# Find what eats /var/log
sudo du -xh /var/log | sort -h | tail -20

# RAM and swap summary
free -h

# Inode exhaustion (common on mail/log servers)
df -i

A full disk stops MySQL, logging, and sessions at once. I check df -h before any deploy on shared EC2 hosts. If logs balloon, rotate or truncate after fixing the root cause—not before you have evidence.

Resource Check Loopdf -hdisk spacefree -hRAM swaphtopCPU loadIdentify bottleneckdisk vs RAM vs runaway processRotate logsdu then truncateRestart servicesystemctl reload
df, free, and htop form the standard Ubuntu health check before restarting services

Ports and listeners

# What listens on 443 and 3306?
sudo ss -tulpn | grep -E ':443|:3306'

# Alternative legacy syntax
sudo netstat -tulpn

ss ships with modern Ubuntu and replaces most netstat use cases. When Nginx shows “address already in use”, ss finds the conflicting PID fast.

Which networking and firewall commands matter most on Ubuntu?

Web developers touch networking more than they expect. SSL renewals, upstream timeouts, and blocked admin ports all start at the shell.

IP, DNS, and HTTP checks

# Addresses and routes
ip addr show
ip route show

# DNS resolution test
dig +short app.example.com A

# HTTP headers from localhost
curl -I http://127.0.0.1
curl -I https://app.example.com

curl -I verifies virtual host routing without loading full page bodies. I use it after installing Nginx on Ubuntu to confirm the correct server block answers.

UFW firewall

sudo ufw status verbose
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable

Always allow SSH before enabling UFW. Locking yourself out costs real time. Our UFW firewall guide walks through safe ordering. For deeper hardening, read server hardening for Ubuntu web servers.

What package and service commands does Ubuntu rely on every day?

Ubuntu 24.04 LTS still centres on apt for PHP 8.3, 8.4, and 8.5 side-by-side setups. Service control goes through systemd. Mixing Snap and apt for the same role causes confusion—pick one path per tool.

APT and dpkg essentials

# Refresh index and upgrade packages
sudo apt update
sudo apt upgrade -y

# Install PHP 8.4 FPM on Ubuntu 24.04
sudo apt install php8.4-fpm php8.4-cli php8.4-mysql

# See which package owns a binary
dpkg -S $(which php)

# List installed PHP packages
dpkg -l 'php8.4-*'

Run apt update before apt install. The index stale error wastes minutes on fresh VPS builds. See apt update explained on Ubuntu for the distinction between update and upgrade.

systemctl and journalctl

# Service state
sudo systemctl status nginx
sudo systemctl status php8.4-fpm

# Reload after config edit (no drop connections)
sudo systemctl reload nginx

# Restart after pool change
sudo systemctl restart php8.4-fpm

# Last 100 lines of Nginx errors
sudo journalctl -u nginx -n 100 --no-pager

# Follow live logs
sudo journalctl -u php8.4-fpm -f

After Deployer symlink swaps, reload PHP-FPM to clear opcache. A restart kicks active requests—use reload when the unit supports it. Official reference: systemd systemctl documentation.

CommandBest forCaution
systemctl reloadNginx config change, graceful refreshUnit must support reload
systemctl restartPHP-FPM pool edits, extension changesBrief request interruption
journalctl -uService-specific errors since bootUse -f sparingly on busy boxes
apt upgradeSecurity patchesTest PHP extensions after kernel/lib upgrades
ss -tulpnPort conflictsRequires sudo for process names

Cron and scheduled tasks

# Edit root crontab
sudo crontab -e

# List Laravel scheduler entry (typical)
* * * * * cd /var/www/current && php artisan schedule:run >> /dev/null 2>&1

# Verify cron service
sudo systemctl status cron

Stale paths in cron are a classic post-deploy bug. The symlink moves but cron still points at an old release directory. After each deploy pattern change, verify with sudo crontab -l. Details sit in our Ubuntu cron jobs guide.

How do you combine commands for real Ubuntu troubleshooting?

Individual commands matter less than sequences. Below are workflows I use on production Laravel and WordPress hosts.

502 Bad Gateway on PHP-FPM

  1. sudo systemctl status php8.4-fpm — is the unit active?
  2. sudo journalctl -u php8.4-fpm -n 50 — pool crash or socket mismatch?
  3. sudo ss -tulpn | grep php — is the socket listening?
  4. grep listen /etc/php/8.4/fpm/pool.d/www.conf — match Nginx fastcgi_pass
  5. sudo systemctl restart php8.4-fpm && sudo systemctl reload nginx

Socket versus TCP mismatches survive many edits because Nginx and pool configs live in different files. Always compare both sides.

Disk full on /var

  1. df -h /var
  2. sudo du -xh /var | sort -h | tail -30
  3. sudo journalctl --disk-usage
  4. Rotate or vacuum logs; expand volume if needed

journalctl --vacuum-time=7d reclaims space when systemd journals dominate. Do not delete random files under /var/lib/mysql.

Permission denied on upload

  1. namei -l /var/www/current/storage/app/public — trace path permissions
  2. stat storage/app/public
  3. sudo chown -R www-data:www-data storage
  4. Confirm SELinux/AppArmor only if enabled (uncommon on default Ubuntu)

namei -l is underrated. It shows which directory in the chain blocks access.

502 Gateway Debug502 errorstatusjournalss portfixCommon root causessocket mismatch, pm.max_children, opcache stalefix pool config then reload servicesPHP 8.4 FPMproduction defaultNginx proxyfastcgi_pass match
502 Bad Gateway debug path using the best Linux commands for Ubuntu users on PHP-FPM stacks

Useful one-liners worth saving

  • history | grep apt — what did I install last week?
  • wc -l storage/logs/laravel.log — log growth sanity check
  • watch -n 2 df -h — live disk during import jobs
  • lsof -i :80 — which process holds port 80
  • sudo nginx -t — test config before reload
  • php -v && php -m — confirm CLI version and modules

For JSON log fragments pasted from terminals, clean payloads with our JSON formatter tool before sharing in tickets.

Commands to treat carefully

Some commands delete or overwrite without confirmation prompts.

  • rm -rf — double-check paths; never run as root on /
  • chmod -R 777 — fix ownership instead
  • dd — disk imaging only when you mean it
  • > /var/log/... truncation — capture evidence first

The GNU coreutils manual remains the authoritative reference for flags and behaviour: GNU Coreutils documentation. Ubuntu-specific packaging docs live at Ubuntu Server Guide — APT.

Key Takeaways

  • Learn ls -lah, find, grep, chmod, and chown first—they solve most deploy and upload failures.
  • Run df -h, free -h, and htop before restarting services; guesswork wastes minutes.
  • Use systemctl plus journalctl -u for Nginx, PHP-FPM, MySQL, and cron—not scattered log files alone.
  • Prefer ss over legacy netstat, and curl -I for quick HTTP checks after config edits.
  • Always apt update before installs, and reload PHP-FPM after Deployer releases to refresh opcache.
  • Build muscle memory with troubleshooting sequences, not isolated command lists.

People Also Ask

What are the most essential Linux commands for Ubuntu beginners?

Start with pwd, cd, ls -lah, cp, mv, mkdir, rm, cat, less, and sudo. Add apt update and apt install on day two. Our essential Ubuntu terminal commands article expands this list with copy-paste examples for desktop and server.

How do I check which Linux commands are installed on Ubuntu?

Use command -v nginx or which php to locate binaries. Run dpkg -l | grep nginx to see package status. For shell builtins, try type cd. Install missing tools with sudo apt install package-name.

What is the difference between apt and apt-get on Ubuntu?

Both use the same underlying APT libraries. The apt command adds progress bars and cleaner output for interactive use. Scripts often keep apt-get for stable, scriptable behaviour. Either works on Ubuntu 24.04 LTS for installs and upgrades.

Which Linux commands help secure an Ubuntu web server?

Combine ufw status, fail2ban-client status, ss -tulpn, and apt list --upgradable. Review last and lastb for SSH attempts. Hardening is a process—see Ubuntu security hardening and professional Linux system administration when production uptime matters.

Put the best Linux commands for Ubuntu users into daily practice

You do not need hundreds of obscure utilities. The best Linux commands for Ubuntu users are the ones tied to real workflows: deploy, debug, secure, and recover. Practice the sequences in this guide on a staging VPS before you need them at 2 a.m.

I use this exact toolkit across Laravel booking apps, legal-tech portals like Adventure Third Pole Trek, and WooCommerce stores on shared infrastructure. When commands are not enough—monitoring, hardening, or migration—support and maintenance or web development services close the gap.

Want help auditing a production Ubuntu stack or fixing recurring deploy failures? Contact us with your server OS version, web stack, and the last error you saw. Bring journalctl output—we can start from facts, not guesses.

Frequently Asked Questions

Navigation (cd, ls, find), packages (apt, dpkg), processes (systemctl, journalctl, htop), networking (ss, ufw), and logs (tail, grep) on Ubuntu 24.04 LTS production servers.

Start with pwd, cd, ls -lah, less, head, and tail for orientation and log reading. Use find to locate large or old logs and grep -R to search PHP-FPM configs under /etc/php/. For deploy work, cp -a preserves symlinks, mv moves release folders, and tar -czf creates quick backups before schema changes. When uploads fail, stat shows owner and numeric mode, while chown and chmod fix Laravel storage and bootstrap/cache. Never chmod 777 on production; set www-data ownership instead.

Run ps aux --sort=-%cpu | head -15 for a CPU snapshot, or htop for an interactive view after sudo apt install htop. Check df -h first—a full /var partition stops MySQL, logging, and sessions. Use sudo du -xh /var/log | sort -h | tail -20 to find log bloat, free -h for RAM and swap, and df -i if inodes are exhausted. For port conflicts, sudo ss -tulpn shows what listens on 443 or 3306. Prefer kill -15 before kill -9 so Laravel queue workers drain gracefully.

Use ip addr show and ip route show for local addressing, dig +short for DNS checks, and curl -I for quick HTTP header tests without loading full pages—handy after Nginx virtual host changes. For firewalls, sudo ufw status verbose shows rules; sudo ufw allow OpenSSH must come before sudo ufw enable, or you risk locking yourself out of SSH. Allow Nginx Full for web traffic. When debugging upstream timeouts or SSL routing, curl -I from localhost confirms which server block answers before you dig into application logs.

Ubuntu 24.04 LTS centres on apt: run sudo apt update before sudo apt install, then sudo apt upgrade -y for security patches. Use dpkg -S $(which php) to see which package owns a binary and dpkg -l 'php8.4-*' to list installed PHP extensions. Service control goes through systemd: systemctl status nginx or php8.4-fpm, systemctl reload nginx after config edits, and systemctl restart php8.4-fpm after pool changes. Pair journalctl -u nginx -n 100 with journalctl -u php8.4-fpm -f for live error tracing. Avoid mixing Snap and apt for the same role.

Trace the full path with namei -l /var/www/current/storage/app/public—it shows which directory blocks access, which is faster than guessing. Inspect the target with stat storage/app/public, then fix ownership: sudo chown -R www-data:www-data storage bootstrap/cache and sudo chmod -R ug+rwx storage bootstrap/cache. After Deployer symlink swaps, wrong chown on storage/ is a common cause of broken uploads. Never chmod 777 on production; fix owner and group instead. On default Ubuntu, SELinux and AppArmor are rarely the culprit unless explicitly enabled.

Work through a fixed sequence. First, sudo systemctl status php8.4-fpm—is the unit active? Then sudo journalctl -u php8.4-fpm -n 50 for pool crashes or socket mismatches. Run sudo ss -tulpn | grep php to confirm the socket is listening, and grep listen /etc/php/8.4/fpm/pool.d/www.conf to match Nginx fastcgi_pass. Socket versus TCP mismatches survive many edits because Nginx and pool configs live in different files—compare both sides. Finish with sudo systemctl restart php8.4-fpm and sudo systemctl reload nginx.

Start with df -h /var to confirm usage, then sudo du -xh /var | sort -h | tail -30 to find the largest directories. Check journal size with sudo journalctl --disk-usage; if systemd journals dominate, reclaim space using journalctl --vacuum-time=7d. Rotate or truncate logs only after capturing evidence—you need the root cause first. A full disk stops MySQL, logging, and sessions at once, so I check df -h before every deploy on shared EC2 hosts. Do not delete random files under /var/lib/mysql.

Both use the same underlying APT libraries. apt adds progress bars and cleaner output for interactive use; apt-get remains common in scripts for stable, scriptable behaviour. Either works on Ubuntu 24.04 LTS for installs and upgrades.

Use command -v nginx or which php to locate binaries on your PATH. Run dpkg -l | grep nginx to see package install status and version. For shell builtins like cd, type cd confirms they are built into the shell rather than external programs. If a tool is missing—htop, tree, or ripgrep—install it with sudo apt install package-name after sudo apt update refreshes the package index. On PHP stacks, dpkg -S $(which php) tells you exactly which package owns the active binary.

Combine sudo ufw status verbose with fail2ban-client status to review firewall and ban rules. Run sudo ss -tulpn to audit open ports and sudo apt list --upgradable for pending security patches. Review last and lastb for SSH login attempts. Use find /var/www -type f -perm -002 to locate world-writable files under a web root during audits. Always allow OpenSSH in UFW before enabling the firewall. Hardening is ongoing—pair these checks with log rotation, timely apt upgrade runs, and sensible file ownership on deploy paths.

Use systemctl reload for Nginx config changes when you need a graceful refresh without dropping active connections—the unit must support reload. Use systemctl restart after PHP-FPM pool edits or PHP extension changes; expect brief request interruption. After Deployer symlink swaps, reload PHP-FPM to clear opcache rather than restarting when reload is supported. journalctl -u service-name surfaces errors since boot; use -f sparingly on busy boxes. Test Nginx configs with sudo nginx -t before any reload to catch syntax errors early.

ss ships with modern Ubuntu and replaces most netstat use cases for checking listeners and port conflicts. Run sudo ss -tulpn | grep -E ':443|:3306' to see what holds HTTPS or MySQL ports, including process names when run with sudo. When Nginx reports address already in use, ss finds the conflicting PID faster than guessing. It fits the same workflows as legacy netstat -tulpn but aligns with current Ubuntu Server tooling. Pair it with curl -I and systemctl status when debugging web stack connectivity.

Edit the root crontab with sudo crontab -e and verify entries with sudo crontab -l after every deploy pattern change. A typical Laravel scheduler line runs php artisan schedule:run every minute from /var/www/current. Confirm the cron daemon with sudo systemctl status cron. Stale paths in cron are a classic post-deploy bug—the symlink moves but cron still points at an old release directory. On sister sites I maintain with Deployer 7 and GitLab CI, this mismatch surfaces repeatedly until someone audits crontab paths against the current symlink.

rm -rf deletes without confirmation—double-check paths and never aim it at root-owned system directories. chmod -R 777 creates audit and security debt; fix www-data ownership instead. dd is for intentional disk imaging only. Redirecting output to truncate /var/log files destroys evidence before you diagnose the root cause—capture logs first. Prefer kill -15 over kill -9 for queue workers. Before service changes, run sudo nginx -t and keep watch -n 2 df -h handy during large imports. The GNU Coreutils manual remains the authoritative reference for flag behaviour.

Share this article

0 Comments

Leave a comment

Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

Quick Contact Options
Choose how you want to connect me: