Every task you will perform as an administrator requires that you understand how to get around the UNIX filesystem. In this lesson you will learn the commands essential for navigation and manipulation of the filesystem.


  • ls, tree

  • pwd

  • cd

  • df

  • pushd, popd, dirs


  • /etc/fstab

Further Reading

What are the things you will do in this lab? What knowledge does will those things draw on? How does it relate to the course?

A Unified Filesystem


UNIX and Linux use a Unified Filesystem. That is a system where all the disk drives in the system (as well as partitions and network drives) are all located in the same file hierarchy. For users used to Microsoft Windows it can be a bit confusing at first. However, Linux users quickly discover how convenient it is for every file path to look the same regardless of where the data is actually located. From an administrator’s standpoint this makes it possible to make your users experience the same on all UNIX machines regardless of whether the user is logged into a machine in the home office or a satellite office.

The text below shows a diagram of the Linux filesystem generated with the tree command:

maximus@phoenix:/$ cd / && tree -d -L 2
├── bin
├── boot
│   ├── efi
│   ├── grub
│   └── lost+found
├── cdrom
├── dev
│   ├── block
│   ├── bsg
│   ├── bus
│   ├── char
│   ├── cpu
│   ├── disk
│   ├── dri
│   ├── fast_group
│   ├── fd -> /proc/self/fd
│   ├── hugepages
│   ├── input
│   ├── lightnvm
│   ├── mapper
│   ├── mqueue
│   ├── net
│   ├── pts
│   ├── serial
│   ├── shm
│   ├── snd
│   ├── ubuntu-vg
│   └── vfio
├── etc
├── home
│   ├── student
├── lib
├── lib32
├── lib64
├── libx32
├── mnt
├── proc
├── root 
├── run
├── sbin
├── sys
│   ├── block
│   ├── bus
│   ├── class
│   ├── dev
│   ├── devices
│   ├── firmware
│   ├── fs
│   ├── hypervisor
│   ├── kernel
│   ├── module
│   └── power
├── tmp
├── usr
│   ├── bin
│   ├── games
│   ├── include
│   ├── lib
│   ├── lib32
│   ├── libx32
│   ├── libx86_64-linux-gnu
│   ├── local
│   ├── locale
│   ├── sbin
│   ├── share
│   └── src
└── var
    ├── backups
    ├── cache
    ├── crash
    ├── lib
    ├── local
    ├── lock -> /run/lock
    ├── log
    ├── mail
    ├── metrics
    ├── opt
    ├── run -> /run
    ├── snap
    ├── spool
    └── tmp

The output has been shortened for clarity. You can generate the complete directory hierarchy with this command:

$ cd /
$ tree -d

The top level directories are organized by function. Different distributions (e.g. Ubuntu and Fedora) have slightly different rules on where files go inside the hierarchy but, for the most part, the organization at the top level is as follows:

Directory Examples Purpose
/bin /bin/ls
Contains many (but not most) of the system's executable programs. The programs here tend to do the most low-level system tasks.
/boot /boot/vmlinuz
Contains the files needed to boot Linux, including the Linux Kernel, which is the core of the operating system, the Initial Ramdisk (initramfs) and the boot loader. On x86-based systems the boot loader is GRUB which is discussed in a different lecture.
/dev /dev/sda
Contains entries for hardware devices. Most peripherals in the system have an entry in this directory. There are some useful virtual devices located here too, such as a random number generator.
/etc /etc/hostname
The etcetera directory (/etc) is where system configuration is stored, such as the system's name, it's IP address, what programs get started at boot time and much more. There are many things you can change about Linux using commands. Making those changes permanent usually means editing a file in the /etc directory
/home /home/student The home directory is typically where user's private data is stored. By default most Linuxes will create a new directory in /home for each user on the system.
/lib, /lib32, /lib64 /lib/ld-linux.so.2
The lib family of directories is where program fragments, called Shared Objects are stored. Shared objects (*.so) files serve the same purpose as DLLs in Windows. They contain program code that many different programs use. The lib directory also holds loadable modules which extend the Linux Kernel's functionality.
/media ./media/cdrom Removable drives often get placed here
/opt /opt/google/chrome Optional or miscellaneous software gets installed here. Most often the /opt directory gets used for commercial software.
/proc, /sys /proc/cmdline
The /proc and /sys directories are very special. The files here are not on any disk, they are a window into the brains of Linux. By reading files /proc and /sys you can answer interesting questions (e.g. What files are open? How hot is my processor?). Writing files in /proc and /sys can alter your system's behavior (e.g. Change the processor clock speed. Hibernate the system.).
/root The home directory of the "root" user.
/run /rsyslogd.pid/run Temporary files used by running programs, usually daemons. Daemons are programs that perform system services. The /run directory stores files in RAM, not the disk so the contents of this directory are lost with every reboot.
/sbin /sbin/init
Binary directory for the system and system administrator. The programs in this directory, like the /bin directory, are usually executable.
/tmp /tmp/foo Temporary data. Unlike /run the data here is stored on disk but Linux periodically cleans out this directory to keep it from becoming full. This is a good place to store files that you don't want to keep. Be careful: Everyone can see the files so don't store private things here.
/usr, /usr/local /usr/bin/vi
The /usr directory contains repeats of some of the top level directories explained here (e.g. /usr/bin, /usr/lib, /usr/sbin). Most software on the system is installed under the /usr directory.
/var /var/log
The var directory holds persistent runtime data (e.g. the system logs). Many system services store data here.