
Understand the Linux directory tree, what lives where, and the essential commands you’ll actually use. Covers Ubuntu/Debian and RHEL family (CentOS/AlmaLinux).
What is the Linux File System?
Linux organizes everything under a single root directory /
. Disks, USB drives, and even virtual files are mounted into this tree. Unlike Windows drive letters (C:, D:), Linux mounts locations to paths like /mnt/data
.
Quick Start: Core Navigation Commands
# where am I?
pwd
# list files with details (human-readable sizes)
ls -alh
# change directory
cd /etc
# create, move, copy, remove
touch notes.txt
mv notes.txt /tmp/
cp /etc/hosts ~/hosts.backup
rm -i ~/hosts.backup
# show a tree of directories (install tree first)
# Ubuntu/Debian:
sudo apt install -y tree
# CentOS/AlmaLinux:
sudo dnf install -y tree
tree -L 2 /
Directory Layout (FHS essentials)
Path | What it’s for | Examples |
---|---|---|
/ | Root of the entire filesystem. | Everything hangs from here. |
/home | User home directories. | /home/alex , /home/tamir |
/root | Home for the root user. | /root/.ssh/ |
/etc | System-wide configuration files (text). | /etc/ssh/sshd_config , /etc/fstab |
/var | Variable data that changes often. | /var/log/ , /var/spool/ , /var/www/ |
/usr | User-space programs & read-only data. | /usr/bin , /usr/lib , /usr/share |
/bin & /sbin | Essential binaries for users/admin. | /bin/ls , /sbin/ip |
/lib & /lib64 | Shared libraries required by binaries. | /lib/x86_64-linux-gnu/ |
/opt | Optional third-party apps. | /opt/google , /opt/zoom |
/srv | Data for services you host. | /srv/ftp , /srv/www |
/tmp | Temporary files (auto-cleaned). | Safe scratch space; not persistent. |
/mnt & /media | Mount points for disks/USBs. | /mnt/data , /media/user/USB |
/dev | Device files (disks, ttys, etc.). | /dev/sda , /dev/tty0 |
/proc & /sys | Virtual kernel info/config. | /proc/cpuinfo , /sys/block/ |
/boot | Bootloader & kernel images. | /boot/vmlinuz , /boot/grub/ |
/run | Runtime state since last boot. | PID files, sockets |
Ubuntu/Debian vs CentOS/AlmaLinux: Key Differences
- Package manager:
apt
(Ubuntu/Debian) vsdnf
(CentOS/Alma). - Default filesystems: Ubuntu/Debian =
ext4
(often), CentOS/Alma =xfs
by default. - Service manager: All use
systemd
, but service names/locations under/etc
may differ. - Web root: Ubuntu’s Apache defaults to
/var/www/html
; RHEL family similar but package names differ.
Hands-On: Common Tasks (Both Families)
Create a directory for a project
mkdir -p ~/projects/talkecoho
cd ~/projects/talkecoho
echo "Hello Linux" > hello.txt
ls -lh
Explore configuration in /etc
# show your hosts file
sudo nano /etc/hosts
# check your network interfaces (systemd-networkd or NetworkManager may manage them)
ip a
View logs in /var/log
# follow the kernel/message log (journalctl spans virtual logs)
sudo journalctl -f
# or read classic log files
sudo tail -n 100 /var/log/syslog # Ubuntu/Debian
sudo tail -n 100 /var/log/messages # CentOS/AlmaLinux
Mount a new disk
# find disk name
lsblk
# create filesystem and mount (example uses /dev/sdb1)
sudo mkfs.ext4 /dev/sdb1
sudo mkdir -p /mnt/data
sudo mount /dev/sdb1 /mnt/data
df -h /mnt/data
# make it persistent across reboots by adding to /etc/fstab:
# UUID=xxxx-xxxx /mnt/data ext4 defaults 0 2
sudo blkid /dev/sdb1
sudo nano /etc/fstab
Permissions & Ownership (Quick Primer)
# see permissions
ls -l
# change owner and group
sudo chown user:group /var/www/html -R
# change permissions (e.g., rwxr-xr-x)
sudo chmod 755 /usr/local/bin/mytool
Typical web directories use 755
for dirs and 644
for files. Never give 777
unless you really know why.
Cheat Sheet by Distro
Ubuntu/Debian
# install software
sudo apt update && sudo apt install -y nginx
# services
sudo systemctl status nginx
sudo systemctl enable --now nginx
CentOS/AlmaLinux
# install software
sudo dnf install -y nginx
# services
sudo systemctl status nginx
sudo systemctl enable --now nginx