Ubuntu Bash Commands
A reference for common terminal commands used when managing a Ubuntu VPS — files, permissions, networking, users, and system utilities.
Files & Folders
Section titled “Files & Folders”Navigate and manage directories and files on the filesystem.
cd /var/www/htmlcd ..cd ~Flags:
.. goes up one level.
~ returns to the root folder.
lsls -lals -lh /var/www/Flags:
-l shows details.
-a includes hidden files.
-h human-readable sizes.
mkdir /path/to/my/websitemkdir /var/www/newsitemkdir -p /var/www/a/b/cFlags:
-p creates all parent folders and won’t error if they exist.
cp file.txt /tmp/file.txtmv oldname.txt newname.txtEdit & Inspect Files
Section titled “Edit & Inspect Files”Create, view and edit files directly in the terminal.
nano /etc/nginx/nginx.confSave with CTRL+X → Y → Enter. Discard with CTRL+X → N →
Enter.
cat /var/www/file.txtDumps an entire file to the terminal.
Always ends with an empty terminal line for a next command.
Use less for long files.
less /var/www/file.txtCreates an overlay to show a full file in the terminal.
Looks like nano, but you cannot edit the file.
Press q to leave the overlay.
touch /var/www/index.phpAlso updates the last-modified timestamp on existing files.
tail -f /var/log/nginx/error.logtail -50 /var/log/syslogFlags:
-f follows the file in real time. Essential for watching logs.
Remove Files & Folders
Section titled “Remove Files & Folders”rm file.txtrm -r my-folder/Flags:
-i Prompts a confirmation for deletion.
-r Deletes a directory recursively.
-f Force delete a file or directory.
rmdir emptyfolderOnly works on completely empty directories. Safer than rm -r.
Permissions & Users
Section titled “Permissions & Users”Control who can read, write, and execute files.
chmod 755 file.shchmod -R 775 /var/www/site/755 → Owner: rwx · Group: r-x · Others: r-x
chown ubuntu:ubuntu file.txtchown -R www-data:ubuntu /var/www/site/Format is user:group. Use -R to apply recursively.
sudo nano /etc/nginx/nginx.confsudo systemctl restart nginxElevates a single command to root. Safer than switching to the root user.
su rootsu - ubuntusu - also loads the target user’s environment variables.
7 → rwx Read + Write + Execute6 → rw- Read + Write5 → r-x Read + Execute4 → r-- Read only0 → --- No accessThree digits = Owner · Group · Others. e.g. 755, 644, 600.
User Management
Section titled “User Management”Create and manage system users. Useful for setting up deploy users or isolating services.
adduser johnWalks you through setting a password and home directory interactively.
usermod -aG sudo johnAdds john to the sudo group. Takes effect on next login.
passwd johnsudo passwd rootRun without arguments to change your own password.
deluser johndeluser --remove-home john--remove-home also deletes their home directory and files.
Network & Connectivity
Section titled “Network & Connectivity”Diagnose connectivity and inspect network configuration.
ping casper-rs.devping -c 4 8.8.8.8-c 4 stops after 4 packets instead of running forever.
curl https://example.comcurl -I https://example.comcurl ifconfig.me-I shows headers only. ifconfig.me returns your public IP.
hostnamehostname -I-I lists all IP addresses assigned to the server.
ss -tlnpShows all listening TCP ports and which process owns them. Replaces netstat.
System & Logs
Section titled “System & Logs”Monitor system health and read service logs.
systemctl status nginxsystemctl restart nginxsystemctl enable php8.3-fpmenable makes a service start automatically on boot.
journalctl -xeu nginxjournalctl -f -u php8.3-fpm-f follows live, -u filters by service name.
tail -f /var/log/nginx/error.logtail -f /var/log/nginx/access.logError log is the first place to check when a site isn’t loading.
df -hfree -hdf -h shows disk usage per partition. free -h shows RAM usage.
htopInteractive CPU/RAM/process viewer. Install with apt install htop if missing.
uptimeuname -ruptime shows how long the server has been running. uname -r shows the kernel
version.