Linucate
~ Linucate_

104.7 Find system files and place files in the correct location

All Levels

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, and type.
  • 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:

  • which returns the command path found in PATH
  • 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:

  • whereis can 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:

  • find searches 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
  1. Run: which bash
  2. Then: type bash
  3. Notice that type gives shell-aware information.
2) Search for config files
  1. Run: find /etc -name "*.conf"
  2. Read it as: search under /etc for files ending in .conf.
3) Use the locate database
  1. Search: locate passwd
  2. 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
  • /proc and /sys = virtual kernel information
  • /run = runtime state
  • /opt = optional software
  • find = live filesystem search
  • locate = database-based search
  • updatedb = refresh locate database
  • which = command path lookup
  • type = shell-aware command lookup
  • whereis = binary/source/man lookup
🎯

Test Your Knowledge

Complete the quiz to assess your understanding of this course's concepts.