Casper-RS avatar
Made by Casper-RS

Files & Folders

Navigate and manage directories and files on the filesystem.

cd — change directory
cd /var/www/html
cd ..
cd ~

Flags:

.. goes up one level.
~ returns to the root folder.

ls — list files
ls
ls -la
ls -lh /var/www/

Flags:

-l shows details.
-a includes hidden files.
-h human-readable sizes.

mkdir — make directory
mkdir /path/to/my/website
mkdir /var/www/newsite
mdir -p /var/www/a/b/c

Flags:

-p creates all parent folders and won't error if they exist.

cp & mv — copy / move
cp file.txt /tmp/file.txt
mv oldname.txt newname.txt

Edit & Inspect Files

Create, view and edit files directly in the terminal.

nano — text editor
nano /etc/nginx/nginx.conf

Save with CTRL+XY → Enter. Discard with CTRL+XN → Enter.

cat — view file
cat /var/www/file.txt

Dumps an entire file to the terminal.
Always ends with an empty terminal line for a next command.
Use less for long files.

less — view file
less /var/www/file.txt

Creates 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 — create empty file
touch /var/www/index.php

Also updates the last-modified timestamp on existing files.

tail — watch file live
tail -f /var/log/nginx/error.log
tail -50 /var/log/syslog

Flags:

-f follows the file in real time. Essential for watching logs.

Remove Files & Folders

Irreversible. There is no recycle bin on Linux.
Deleted files are gone immediately.

Never run rm -rf without being certain of the path.

rm — remove file
rm file.txt
rm -r my-folder/

Flags:

-i Prompts a confirmation for deletion.
-r Deletes a directory recursively.
-f Force delete a file or directory.

rmdir — remove empty dir
rmdir emptyfolder

Only works on completely empty directories. Safer than rm -r.

Permissions & Users

Control who can read, write, and execute files.

chmod — change permissions
chmod 755 file.sh
chmod -R 775 /var/www/site/

755 → Owner: rwx · Group: r-x · Others: r-x

chown — change owner
chown ubuntu:ubuntu file.txt
chown -R www-data:ubuntu /var/www/site/

Format is user:group. Use -R to apply recursively.

sudo — run as root
sudo nano /etc/nginx/nginx.conf
sudo systemctl restart nginx

Elevates a single command to root. Safer than switching to the root user.

su — switch user
su root
su - ubuntu

su - also loads the target user's environment variables.


Permission values
7 → rwx  Read + Write + Execute
6 → rw-  Read + Write
5 → r-x  Read + Execute
4 → r--  Read only
0 → ---  No access

Three digits = Owner · Group · Others. e.g. 755, 644, 600.

User Management

Create and manage system users. Useful for setting up deploy users or isolating services.

Add a new user
adduser john

Walks you through setting a password and home directory interactively.

Give sudo access
usermod -aG sudo john

Adds john to the sudo group. Takes effect on next login.

Change password
passwd john
sudo passwd root

Run without arguments to change your own password.

Delete a user
deluser john
deluser --remove-home john

--remove-home also deletes their home directory and files.

Network & Connectivity

Diagnose connectivity and inspect network configuration.

ping — test connectivity
ping casper-rs.dev
ping -c 4 8.8.8.8

-c 4 stops after 4 packets instead of running forever.

curl — HTTP requests
curl https://example.com
curl -I https://example.com
curl ifconfig.me

-I shows headers only. ifconfig.me returns your public IP.

hostname — server identity
hostname
hostname -I

-I lists all IP addresses assigned to the server.

ss — open ports
ss -tlnp

Shows all listening TCP ports and which process owns them. Replaces netstat.

System & Logs

Monitor system health and read service logs.

systemctl — manage services
systemctl status nginx
systemctl restart nginx
systemctl enable php8.3-fpm

enable makes a service start automatically on boot.

journalctl — service logs
journalctl -xeu nginx
journalctl -f -u php8.3-fpm

-f follows live, -u filters by service name.

Nginx log files
tail -f /var/log/nginx/error.log
tail -f /var/log/nginx/access.log

Error log is the first place to check when a site isn't loading.

df & free — disk & memory
df -h
free -h

df -h shows disk usage per partition. free -h shows RAM usage.

htop — process monitor
htop

Interactive CPU/RAM/process viewer. Install with apt install htop if missing.

uptime & uname
uptime
uname -r

uptime shows how long the server has been running. uname -r shows the kernel version.