Linux File System Basics

💤0
Lv 10 XP
← 🧱 Foundations · Linux Fundamentals

Linux File System Basics

Beginner ⭐ 50 XP ⏱ 18 min #linux#filesystem#cli

Understand how Linux organizes everything as files in a single tree, and learn to move around it with confidence.

📖Theory

In Linux, everything is a file — your documents, your hard drives, even your keyboard and network connections. All of these live in a single upside-down tree that starts at the root directory, written as /.

There is no C: or D: drive like on Windows. Instead, additional disks are mounted into folders inside that one tree. This single-tree idea is the most important mental model in Linux.

A few key directories you’ll meet everywhere:

  • / — the root of everything
  • /home — personal folders (yours is /home/yourname, shortened to ~)
  • /etc — system-wide configuration files
  • /var — files that change a lot, like logs (/var/log)
  • /usr — installed programs and their data
  • /tmp — temporary scratch space, wiped on reboot
graph TD
  R["/ (root)"] --> H["/home"]
  R --> E["/etc"]
  R --> V["/var"]
  R --> U["/usr"]
  R --> T["/tmp"]
  H --> A["/home/alex"]
  V --> L["/var/log"]
  A --> N["notes.txt"]
The Linux filesystem is one tree rooted at /
🌍Real-World Example

Imagine you just logged in. Here’s a quick tour of finding your way around:

pwd                 # print working directory -> /home/alex
ls -la              # list everything, including hidden dotfiles
cd /var/log         # jump to the system logs
cd ~                # go home (~ is shorthand for /home/alex)
cd ..               # move up one directory
tree -L 1 /         # see the top level of the whole tree

The combination of pwd, ls, and cd is how you build a mental map of any machine you land on — even one you’ve never seen before.

✍️Hands-On Exercise

Try these on any Linux machine (or WSL / a container):

  1. Find your home directory’s absolute path with pwd.
  2. List all files in /etc that start with h — hint: ls /etc/h*.
  3. Create a folder ~/practice, move into it, then create an empty file with touch hello.txt. Confirm with ls -l.
  4. From inside ~/practice, navigate to /var/log using one cd command, then return to ~/practice using cd - (jump back).
🧾Cheat Sheet
CommandWhat it does
pwdShow current directory
ls -laList all files (long, including hidden)
cd <dir>Change directory
cd ~ / cdGo to home
cd -Go to previous directory
mkdir -p a/b/cMake nested directories
touch fileCreate an empty file / update timestamp
cp -r src dstCopy (recursively)
mv src dstMove or rename
rm -r dirRemove recursively (careful!)
find / -name fooSearch the tree by name
du -sh dirDisk usage of a directory
💬Common Interview Questions
What does the root directory `/` represent?

It’s the single top of the entire Linux filesystem tree. Every file and every mounted disk lives somewhere underneath it — there are no separate drive letters.

What's the difference between an absolute and a relative path?

An absolute path starts from / and is unambiguous from anywhere (/home/alex/file). A relative path is interpreted from your current working directory (./file, ../file).

Where would you look for application logs on a typical Linux system?

/var/log — for example /var/log/syslog, /var/log/auth.log, or service- specific subfolders. On systemd machines you’d also use journalctl.

🚑Troubleshooting Scenarios

“No such file or directory” when you’re sure it exists. You’re probably using a relative path from the wrong location. Run pwd to see where you actually are, then use an absolute path or cd to the right place.

rm -rf deleted more than you expected. A stray space turns rm -rf ./build into rm -rf . /build. Always double-check the path, and prefer ls first to preview what a glob matches.

“Permission denied” reading a file in /etc or /var. System files are often owned by root. Read them with sudo cat <file>, but only edit configuration you understand.

📚Official Documentation

📝 My notes on this topic

Auto-saves as you type