Skip to content
$ lynuxpro
← Linux

LESSON 2 OF 26 · BEGINNER · 15 MIN

Navigating the filesystem

In one minute

  • The filesystem is how Linux keeps every file and folder. It is one big tree that starts at / (called root).
  • On a server you have no mouse and no file explorer. To fix anything, you first need to get to the right file: a config, a log, a program.
  • Think of a building. / is the main door. Every folder is a room, and rooms can have smaller rooms inside. A path like /var/log/nginx is the directions: "go in the main door, then room var, then room log, then room nginx".
  • 👉 Every time you log in to a server. Before you read a log, edit a config or run an app, you first move to where it lives.

There are no drive letters like C: or D:. A second disk or a USB drive does not get its own letter. It shows up as a folder somewhere inside the same tree.

The directory tree

Linux puts the same kinds of files in the same places on every server.

Once you learn the map, you can find things on any Linux machine, even one you have never seen.

Learn the main folders below. You do not need all of them on day one. Start with the four in bold.

PathWhat lives thereWhen you go there
/The top of the treeRarely directly
/home/<user>Each user's personal files (short form: ~)Your scripts, keys and notes
/rootThe home folder of the admin user, rootAdmin work
/etcSettings (configuration) for the system and appsChanging nginx, SSH or DNS settings
/var/logLog files: what programs wrote about what they didDebugging anything
/var/libApp data (databases, Docker images)When the disk is full
/tmpTemporary files, often deleted on rebootScratch work
/usr/bin, /binInstalled programs (commands)Finding where a command lives
/optSoftware installed by hand, not by the package managerVendor apps, your own apps
/proc, /sysNot real files: live info from the running systemCPU, memory and hardware info
/devFiles that stand for devices (disks, terminals)Storage work
/mnt, /mediaPlaces to attach extra disksAdding a disk

Remember it: "Etc = Edit settings. Var/log = View all records. Home = my stuff."

Where am I? pwd

pwd prints the folder you are in right now. It stands for print working directory.

Every command runs "inside" a folder. If you are in the wrong folder, commands can act on the wrong files.

👉 Any time you are not sure where you are. It never changes anything, so it is always safe.

pwd
SHELLbashutf-8 · 1L
/home/lynuxpro
OUTPUTterminalutf-8 · 1L

What is in here? ls

ls lists (shows) the files and folders in a folder.

Before you open, copy or delete something, you want to see what is there.

Type ls on its own for the current folder, or add a path to look somewhere else without moving.

lsls -lls -lals -lh /var/log
SHELLbashutf-8 · 4L
total 16-rw-r--r-- 1 lynuxpro lynuxpro   153 Nov 28 09:42 README.txt-rw-r--r-- 1 lynuxpro lynuxpro    86 Nov 28 09:42 notes.txt
OUTPUTterminalutf-8 · 3L

Options (also called flags) change how a command behaves. These are the useful ones for ls:

OptionMeaningMemory trick
-lLong format: permissions, owner, size, datel = long
-aShow hidden files too (names that start with a dot, like .bashrc)a = all
-hSizes people can read (4.0K, 12M), used with -lh = human
-tNewest firstt = time
-rReverse the orderr = reverse
-RAlso list everything inside subfoldersBig R = go deep (Recursive)

You can join short options together: ls -la is the same as ls -l -a.

A favourite: ls -lart shows everything in long format, oldest first. So the file that changed most recently sits at the bottom, right above your cursor, where your eyes already are.

Reading a long listing

ls -l prints one line per file, packed with information.

It answers "who owns this, can I change it, how big is it, when did it change?" in one look.

Read the line from left to right:

-rw-r--r-- 1 lynuxpro lynuxpro 153 Nov 28 09:42 README.txt
OUTPUTterminalutf-8 · 1L
FieldExampleMeaning
Type and permissions-rw-r--r--First letter: - file, d folder (directory), l link. Then who can read, write and run it
Links1How many names point to this file (you can ignore this for now)
OwnerlynuxproThe user who owns the file
GrouplynuxproThe group that owns the file
Size153Size in bytes
DateNov 28 09:42When it was last changed
NameREADME.txtThe file name

Permissions have their own lesson later. For now, just notice the first letter: d means folder.

Moving around: cd

cd moves you into another folder. It stands for change directory.

It is how you walk around the tree, like walking from room to room.

👉 Constantly: before reading logs, editing configs or running anything in a folder.

cd /var/logpwdcd ..pwdcd ~pwdcd -
SHELLbashutf-8 · 7L
CommandGoes toThink of it as
cd /etcThat exact folder"Take me to this address"
cd projectsA folder inside the one you are in"Go into the next room"
cd ..One level up"Step back out of this room"
cd ../..Two levels up"Step back twice"
cd ~ or just cdYour home folder"Go home"
cd -The folder you were in before"Go back where I just was"

Absolute and relative paths

A path is the directions to a file. There are two kinds:

  • An absolute path starts with /. It is the full address from the main door: /etc/nginx/nginx.conf. It works from anywhere.
  • A relative path starts from where you are now. If you are in /etc, then nginx/nginx.conf points to the same file.

Two special short names:

  • . means "this folder".
  • .. means "the folder above this one" (the parent).

Why it matters: A relative path only works if you are standing in the right place. An absolute path always works.

How to choose:

  • Typing by hand? Relative paths are quicker.
  • Writing a script or a cron job (a scheduled task)? Always use absolute paths. Scripts often run from a different folder than you expect, and relative paths then point to the wrong place.

Remember it: Absolute = full home address. Relative = "two doors down from here".

Seeing the shape of a folder: tree

tree draws a folder and everything inside it as a picture.

It is the fastest way to understand how a project or config folder is laid out.

👉 Opening a project or config folder for the first time.

tree /etc/nginx
SHELLbashutf-8 · 1L
/etc/nginx└── nginx.conf0 directories, 1 files
OUTPUTterminalutf-8 · 4L

tree is not installed on every server. find (covered in a later lesson) always is.

Tab completion and history: the two biggest time savers

The shell can finish names for you (Tab) and remember what you typed before (history).

Less typing means fewer typos and much faster work. Tab also proves a file exists: if Tab will not complete it, the name is wrong.

  • Press Tab to finish a command, file or folder name. If there is more than one match, press Tab twice to see them all.
  • Press ↑ and ↓ to scroll through earlier commands.
  • Run history to see the full list.

Try it now in the terminal: type cd /var/l and press Tab.

history
SHELLbashutf-8 · 1L

Real-world scenario

An alert says the nginx web server is failing. You log in to the server and go straight to the right places:

cd /etc/nginxls -lcd /var/log/nginxls -lttail -n 3 /var/log/nginx/access.log
SHELLbashutf-8 · 5L
  • Settings are in /etc, so you check the config there.
  • Logs are in /var/log, so you look at the newest log file there.

Because you know the map, you find the problem in seconds instead of searching.

Common mistakes

  • Spaces in names. cd My Folder fails, because the shell sees two words. Use quotes: cd "My Folder". Better still, do not use spaces in names.
  • Mixing up / and ~. / is the top of the whole system. ~ is your home folder.
  • Relative paths in scripts. They break as soon as the script runs from another folder.
  • Capital letters. Linux cares about case: Notes.txt and notes.txt are two different files.

Practice

  1. Go to /var/log, list it newest first with ls -lt, then go back home with one command.
  2. From your home folder, list /etc without moving there.
  3. Use cd - to jump between /etc and /var/log three times.
  4. Use Tab to type /etc/os-release with as few key presses as you can, then show it with cat.

Cheat sheet

CommandWhat it does
pwdShow where I am
ls -laList everything, including hidden files
ls -ltList newest first
cd pathMove to a folder
cd .. / cd - / cd ~Up one / back to previous / home
treeDraw the folder structure
historyShow earlier commands

Key takeaways

  • Linux keeps every file in one big tree that starts at /.
  • Settings live in /etc, logs in /var/log, and your own files in /home.
  • pwd tells you where you are, ls shows what is there, and cd moves you.
  • A full path starts with / and works from anywhere. Use full paths in scripts.
  • Press Tab to finish names for you.