LearnWithShobhan

The Linux directory structure explained: what /bin, /etc, /home, /var and /tmp are for

Shobhan Biswas··4 min read
>_From the course CLI Mastery: 57 lessons, lifetime access.

Open a Linux or macOS terminal, run ls /, and you get a short list of strangely named folders: bin, etc, var, usr. They look random. They are not. Every one has a job, and once you know them, finding a config file, a log or a program stops being guesswork.

It is one big tree

Unlike Windows, which has separate drives such as C: and D:, Unix-style systems have a single tree. The top of it is called the root directory, written as a single forward slash: /. Everything else, every file, folder and even external drive, lives somewhere underneath it.

bash
$ ls /
bin boot dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var

This is typical output on a Linux server. Your own machine may show a slightly different list.

The folders you will actually meet

DirectoryWhat it is for
/The root of the whole tree.
/binEssential programs (binaries) the operating system needs, such as ls, cp and mkdir. See how the shell finds them.
/bootFiles used to boot the system. Leave it alone.
/devDevices appear here as files: disks, terminals and special ones like /dev/null.
/etcSystem-wide configuration files.
/homeEach user's personal files, one folder per user.
/libShared libraries that programs rely on.
/tmpTemporary files, usually cleared on reboot.
/usrSoftware and programs installed for users, with its own bin and lib inside.
/varVariable data that keeps changing: logs, caches, queues.

Two practical examples: if a web server is misbehaving, its logs are usually under /var/log, and its settings are usually under /etc.

Your home folder, and the ~ shortcut

A computer can have many users, and each one's personal files go under the home directory. On most Linux systems that is /home/yourname. On macOS the same idea is called /Users/yourname.

You almost never type that full path, because the shell gives you a shortcut: the tilde, ~, always means your own home folder.

cd ~
pwd
bash
$ cd ~
$ pwd
/Users/shobhan

So you now know the two most useful symbols in the filesystem: / is the root of everything, and ~ is your home.

macOS vs Linux, quickly

  • macOS puts users in /Users, not /home.
  • External drives on macOS show up under /Volumes; on Linux you will usually find them under /media or /mnt.
  • Both are Unix-style, so /bin, /etc, /usr, /tmp and /var will feel familiar on either.

Where to go next: absolute and relative paths

Knowing the map is half of it. The other half is telling the shell where you want to go. /home/shobhan/notes.txt is an absolute path because it starts at the root. notes.txt or ../notes.txt are relative paths because they start from where you currently are. We explain that clearly, with diagrams, in Absolute vs relative path in Linux. Permissions on these folders are the next piece, covered in Linux file permissions explained.

Free to watch. Get all 57 lessons →

Key takeaways

  • ✓Unix-style systems have one tree. Its top is the root directory, written as /.
  • ✓bin holds essential programs, etc holds configuration, home holds user files, var holds changing data like logs, tmp holds temporary files.
  • ✓~ is a shortcut for your own home folder: /home/name on most Linux systems, /Users/name on macOS.
  • ✓Names differ between distributions and macOS, so learn the idea behind each folder rather than one exact list.

Learn the terminal properly, once

CLI Mastery is 57 short lessons that take you from "what is a shell" to scripting and running a web server on AWS. Every idea is drawn first, then done live. Lifetime access, and three lessons are free to watch.

Free download

Linux command line cheat sheet

One printable page: navigation, files, permissions, pipes, processes, scripts and SSH.

Occasional emails with new tutorials and courses. Unsubscribe any time.

Keep reading