Introduction
This lesson is about the Filesystem Hierarchy Standard, or FHS.
The main question is:
Where should files live on a Linux system, and how do you find them when you need them?
What you should be able to do after this lesson:
- Recognize common top-level directories and their roles.
- Use tools such as
find,locate,whereis,which, andtype. - Place files in sensible locations.
Big Idea: Linux Has Structure for a Reason
If every program put files anywhere it wanted, administration would be chaos.
The FHS gives a shared map. You do not need every detail by heart, but you should know the important places.
Important Directories
/etc
System-wide configuration.
/bin and /sbin
Important command binaries.
On some modern systems these may be linked into /usr.
/usr
Userland programs, libraries, docs, and shared data.
/var
Variable data such as:
- logs
- caches
- spool files
/home
User home directories.
/tmp
Temporary files.
/boot
Bootloader files, kernel, initramfs.
/lib and /lib64
Essential libraries.
/dev
Device nodes.
/proc
Virtual process and kernel information.
/sys
Virtual hardware and kernel state information.
/run
Runtime state data since boot.
/opt
Optional add-on software.
Other useful directories to recognize
/srv= service data for services offered by the system/root= home directory of the root user/usr/local= locally installed software outside the distro package set
Find Commands and Files
which
Find command in PATH:
which ls
Example output:
/usr/bin/ls
What this shows:
whichreturns the command path found inPATH- the exact location depends on the command you ask for
type
Ask the shell what a command really is:
type cd
type ls
whereis
Find binary, source, and manual locations:
whereis bash
Example output:
bash: /usr/bin/bash /usr/lib/bash /usr/include/bash /usr/share/man/man1/bash.1.gz /usr/share/info/bash.info.gz
What this shows:
whereiscan return several useful locations at once- it is broader than
which
find
Deep filesystem search:
find /etc -name "*.conf"
Example output:
/etc/mdadm.conf
/etc/preload.conf
/etc/glusterfs/gsyncd.conf
/etc/fuse.conf
/etc/ld.so.conf
/etc/request-key.conf
What this shows:
findsearches the live filesystem- it is useful when you know the type of file but not the exact path
locate
Fast database-based search:
locate ssh_config
If results seem old, refresh the database:
sudo updatedb
Common config file:
/etc/updatedb.conf
A Practical Placement Mindset
Where should a file go?
- system config ->
/etc - logs ->
/var/log - user files ->
/home/user - temporary work files ->
/tmp - optional third-party app bundle -> often
/opt
If you place files in the wrong area, the system becomes harder to manage.
Practice Step by Step
1) Find where a command comes from
- Run:
which bash - Then:
type bash - Notice that
typegives shell-aware information.
2) Search for config files
- Run:
find /etc -name "*.conf" - Read it as:
search under
/etcfor files ending in.conf.
3) Use the locate database
- Search:
locate passwd - If results are outdated:
sudo updatedb
Cheat Sheet
/etc= system config/usr= programs and shared data/var= changing data such as logs/home= user home directories/tmp= temporary files/boot= boot files/dev= device nodes/procand/sys= virtual kernel information/run= runtime state/opt= optional softwarefind= live filesystem searchlocate= database-based searchupdatedb= refresh locate databasewhich= command path lookuptype= shell-aware command lookupwhereis= binary/source/man lookup
Test Your Knowledge
Complete the quiz to assess your understanding of this course's concepts.
