Linux and Bash course menu
The Linux File System Explained: /etc, /var, /home and Paths
Understand the Linux directory structure: the root folder, /home, /etc, /var, /usr, /tmp and more, absolute and relative paths, hidden files, and why everything is a file.
On this page
Windows has drives such as C:\. Linux has one tree, starting at a single folder called the root, written /. Everything sits somewhere below it, even other disks and USB sticks.
ls /bin
bin.usr-is-merged
boot
dev
etc
home
imagegeneration
lib
lib.usr-is-merged
lib32
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
sbin.usr-is-merged
snap
srv
swapfile
sys
tmp
usr
varThe important folders#
You do not need to memorise them, but /home, /etc, /var/log and /tmp come up constantly.
Everything is a file#
Linux represents most things as files, even information about the system. You can read these with normal commands:
cat /etc/hostname
head -n 2 /etc/os-release
grep -c processor /proc/cpuinfo
ls -l /binlaviyx
PRETTY_NAME="Ubuntu 24.04.5 LTS"
NAME="Ubuntu"
2
lrwxrwxrwx 1 root root 7 Apr 22 2024 /bin -> usr/binThe l at the start of the last line means a symbolic link, a shortcut to another location.
Absolute and relative paths#
A path says where a file is.
- An absolute path starts at
/, and it means the same thing wherever you are. - A relative path starts from your current folder.
pwd
cat /home/asha/work/reports/june.txt
cat work/reports/june.txt
cd work/images
cat ../reports/june.txt
cd ~/home/asha
Sales
Sales
SalesAll three commands read the same file.
Scripts should usually use absolute paths, because a relative path depends on where the script was started.
See the structure#
tree draws folders. It may need installing first (sudo apt install tree):
tree workwork
├── images
└── reports
└── june.txt
3 directories, 1 fileLinks#
A symbolic link points to another path:
ln -s work/reports/june.txt latest.txt
ls -l latest.txt
cat latest.txtlrwxrwxrwx 1 asha asha 21 Nov 5 06:28 latest.txt -> work/reports/june.txt
SalesIf the original is deleted, the link is left "dangling", and it no longer works.
Hidden files#
Names that start with a dot are hidden from a plain ls. They are often settings, such as .bashrc, the file that configures your shell:
ls -A | grep '^\.'.bash_logout
.bashrc
.profileCommon mistakes#
Practice#
Practice exercise
Print the first line of /etc/passwd, then count how many files and folders are directly inside /etc that end in .conf.
Show hint
head -n 1 prints the first line. ls /etc/*.conf | wc -l counts names.
Show solution
head -n 1 /etc/passwd
ls -d /etc/*.conf | wc -lroot:x:0:0:root:/root:/bin/bash
34Key takeaway#
Finished this lesson?