The file system: pwd, ls, cd and where things live
In this lesson
Move around a Linux server with pwd, ls and cd, tell absolute paths from relative ones, and know what /etc, /var, /opt and /home are for.
On this page
A Linux server has no drive letters and no desktop. Everything, including disks, devices and running processes, hangs off one tree that starts at /. This lesson shows how to move through that tree and where to look when you need a config file, a log or a deployed app.
Why this matters#
When something breaks on a server, the first question is "where is it?": the config, the log, the code. Engineers who know the standard layout find these in seconds, and they also put their own files in the right place so the next person can find them too. Paths are also the most common source of small deploy bugs, so it pays to be exact.
One tree, one root#
The top of the tree is called the root directory and is written /. Do not confuse it with the user named root, whose home folder is /root. A path is a list of folder names separated by slashes, ending in a file or folder.
pwd prints the folder you are in right now. ls lists what is inside it. cd moves you somewhere else.
pwd
ls
ls -l/srv/app
current
releases
shared
total 8
lrwxrwxrwx 1 root root 17 Dec 2 20:42 current -> releases/20261202
drwxr-xr-x 4 root root 4096 Dec 2 20:42 releases
drwxr-xr-x 3 root root 4096 Dec 2 20:42 sharedThis is a small deploy folder like the ones you will meet later in the module. The long listing (-l) shows the type and permissions first (d means a directory, l a link), then the owner and group, size, modification time and name. The line for current ends with an arrow: it is a symbolic link pointing to releases/20261202. Lesson 3 covers links; for now just notice how a deploy tool can switch versions by changing one link.
Useful ls options:
-ashows hidden files, which are the ones whose names start with a dot, such as.envand.bashrc.-hprints sizes like4.0Kinstead of raw bytes (use it with-l).-tsorts by modification time, newest first, and-Ssorts by size, biggest first.-dlists a folder itself instead of its contents.ls -ld /rootshows the folder's permissions.
ls -la sharedtotal 12
drwxr-xr-x 3 root root 4096 Dec 2 20:42 .
drwxr-xr-x 4 root root 4096 Dec 2 20:42 ..
-rw-r--r-- 1 root root 0 Dec 2 20:42 .env
drwxr-xr-x 2 root root 4096 Dec 2 20:42 logsWithout -a, you would see only logs and might never notice the .env file. Hidden files are not secret; they are just left out of the default view. The two special entries . and .. always exist: . is the folder itself and .. is its parent.
Absolute and relative paths#
An absolute path starts with / and means the same thing wherever you are: /etc/hostname. A relative path does not start with / and is read from your current folder: releases/20261202.
cd /srv/app/releases/20261202
pwd
cd ../..
pwd/srv/app/releases/20261202
/srv/app.. means "one folder up", so ../.. goes up two. Some other shortcuts worth knowing:
cdwith no argument, orcd ~, goes to your home folder. Bash expands~to the value of$HOME.cd -jumps back to the previous folder and prints its name. It is the "back button"..is the current folder, as in./myscriptfrom lesson 1.
Use absolute paths in scripts, cron jobs and service files. A script that says cd releases works only when it is started from the right folder, and a service started by the system does not start from the folder you expect. Relative paths are fine for quick work at the prompt.
Following links#
When a folder is reached through a symbolic link, pwd shows the path you used. pwd -P shows the real path with links resolved.
cd /srv/app/current
pwd
pwd -P/srv/app/current
/srv/app/releases/20261202If a program tells you it is running from a strange releases/... folder when you thought you were in current, this is why.
Spaces and special characters#
The shell splits words on spaces, so a name with a space needs quotes: cd "My Reports". Better still, avoid spaces in names you create. Use lowercase letters, digits, hyphens and underscores. Linux is case sensitive, so App.log and app.log are two different files.
What the standard folders are for#
Linux distributions follow a common layout. You do not need to memorise all of it, but these four come up daily.
/etcholds system-wide configuration, mostly plain text files. Web server settings, SSH settings and the hostname live here. The name is historical; read it as "settings"./varholds data that changes while the system runs. The most important part is/var/log, where services write logs. Package caches and mail queues are here too./optis for add-on software that comes as one self-contained bundle, such as a vendor's tool. Many teams also put an app here, for example/opt/myapp./homeholds one folder per user, such as/home/deploy. This is where a person's files and dotfiles go. The exception isroot, who uses/root.
A few more are worth recognising:
/usrholds installed programs and libraries./usr/binis where most commands live./tmpis scratch space that anyone can write to. Files here may be deleted on reboot, so never keep anything important there./srvis meant for data a server hands out, such as website files. Some teams deploy apps under/srv/app, which is what the examples here use./procand/sysare not real disk folders. They are windows into the kernel, which you will use when looking at processes.
You can see the real layout of the machine you are on:
ls -d /etc /var /opt /home /tmp /usr /root /srv
ls /var/log | head -6/etc
/home
/opt
/root
/srv
/tmp
/usr
/var
README
alternatives.log
apt
btmp
dpkg.log
faillogExactly what you see in /var/log depends on the machine and which services are installed.
A layout for deployed apps#
Putting an app under /srv/app or /opt/app with three folders keeps things tidy. The release folders hold code, shared holds things that must survive a deploy (logs, uploaded files, the .env), and current points at the live release.
/srv/app/
current -> releases/20261202
releases/
20261201/
20261202/
shared/
.env
logs/Rolling back is then a matter of pointing current at the previous release. The capstone lesson builds on this layout.
Try it#
- Run
pwd, thencd /etc, thenpwd, thencd -. Where didcd -take you? - List
/var/logwithls -ltand find which file was changed most recently. Then tryls -lSand compare. - Create the deploy layout with
mkdir -p ~/demo/srv/app/releases/20261202 ~/demo/srv/app/shared/logsand then usels -R ~/demoto see it. - From inside
~/demo/srv/app/releases/20261202, reachshared/logsusing a relative path made only of..and folder names. Then reach it again with an absolute path. - Create a hidden file with
touch ~/demo/.env. Show thatls ~/demodoes not list it andls -a ~/demodoes.
Sign in to keep track of the lessons you finish.