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/nginxis the directions: "go in the main door, then roomvar, then roomlog, then roomnginx". - 👉 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.
| Path | What lives there | When you go there |
|---|---|---|
/ | The top of the tree | Rarely directly |
/home/<user> | Each user's personal files (short form: ~) | Your scripts, keys and notes |
/root | The home folder of the admin user, root | Admin work |
/etc | Settings (configuration) for the system and apps | Changing nginx, SSH or DNS settings |
/var/log | Log files: what programs wrote about what they did | Debugging anything |
/var/lib | App data (databases, Docker images) | When the disk is full |
/tmp | Temporary files, often deleted on reboot | Scratch work |
/usr/bin, /bin | Installed programs (commands) | Finding where a command lives |
/opt | Software installed by hand, not by the package manager | Vendor apps, your own apps |
/proc, /sys | Not real files: live info from the running system | CPU, memory and hardware info |
/dev | Files that stand for devices (disks, terminals) | Storage work |
/mnt, /media | Places to attach extra disks | Adding 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/home/lynuxproWhat 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/logtotal 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.txtOptions (also called flags) change how a command behaves. These are the useful ones for ls:
| Option | Meaning | Memory trick |
|---|---|---|
-l | Long format: permissions, owner, size, date | l = long |
-a | Show hidden files too (names that start with a dot, like .bashrc) | a = all |
-h | Sizes people can read (4.0K, 12M), used with -l | h = human |
-t | Newest first | t = time |
-r | Reverse the order | r = reverse |
-R | Also list everything inside subfolders | Big 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| Field | Example | Meaning |
|---|---|---|
| Type and permissions | -rw-r--r-- | First letter: - file, d folder (directory), l link. Then who can read, write and run it |
| Links | 1 | How many names point to this file (you can ignore this for now) |
| Owner | lynuxpro | The user who owns the file |
| Group | lynuxpro | The group that owns the file |
| Size | 153 | Size in bytes |
| Date | Nov 28 09:42 | When it was last changed |
| Name | README.txt | The 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 -| Command | Goes to | Think of it as |
|---|---|---|
cd /etc | That exact folder | "Take me to this address" |
cd projects | A 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 cd | Your 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, thennginx/nginx.confpoints 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/etc/nginx└── nginx.conf0 directories, 1 filestree 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
historyto see the full list.
Try it now in the terminal: type cd /var/l and press Tab.
historyReal-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- 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 Folderfails, 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.txtandnotes.txtare two different files.
Practice
- Go to
/var/log, list it newest first withls -lt, then go back home with one command. - From your home folder, list
/etcwithout moving there. - Use
cd -to jump between/etcand/var/logthree times. - Use Tab to type
/etc/os-releasewith as few key presses as you can, then show it withcat.
Cheat sheet
| Command | What it does |
|---|---|
pwd | Show where I am |
ls -la | List everything, including hidden files |
ls -lt | List newest first |
cd path | Move to a folder |
cd .. / cd - / cd ~ | Up one / back to previous / home |
tree | Draw the folder structure |
history | Show 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. pwdtells you where you are,lsshows what is there, andcdmoves you.- A full path starts with
/and works from anywhere. Use full paths in scripts. - Press Tab to finish names for you.