Navigating the Linux Filesystem
The question behind every shell command
Section titled “The question behind every shell command”Open the Terminal application inside your course VM.
The terminal gives us a text-based way to interact with Linux. The program reading the commands you type is called a shell. We will eventually use the shell to inspect programs, process logs, search through files, and connect tools together. For now, we need to answer a more basic question:
Where am I, and what is around me?
That question sounds almost insultingly simple. It is also the source of an impressive number of mistakes. A command that operates on notes.txt needs to know which notes.txt you mean. A program that writes output needs somewhere to put it. A researcher who cannot identify the current directory will eventually inspect the wrong file and develop a very confident explanation of something that never happened.
Your location is part of every shell command, even when the location is not written in the command.
The filesystem is a tree
Section titled “The filesystem is a tree”Linux organizes files and directories into a tree. A directory is a container that can hold files and other directories. Other operating systems often call one a folder; the terms refer to the same basic idea.
At the top of the tree is the root directory, written as a single forward slash:
/Everything else is located somewhere beneath it.
This root directory is not the same thing as the root user account, and it is not your home directory. Linux reused a word in several related places because apparently one source of beginner confusion was insufficient.
Your home directory is the part of the filesystem intended for your files and settings. If your username is student, it will normally be:
/home/studentThe shell also uses a tilde as shorthand for your home directory:
~Find your current location with pwd
Section titled “Find your current location with pwd”The shell keeps track of a current working directory. This is the directory from which relative paths are interpreted.
Run:
pwdpwd stands for print working directory. If your username is student, the output will probably resemble:
/home/studentThe shell prompt may already display part of this location. Do not rely on that. Prompt designs vary, shorten long paths, and sometimes omit the location entirely. pwd asks the shell directly.
List what is around you
Section titled “List what is around you”Run:
lsls lists directory contents. On Ubuntu Desktop, you may see names such as:
Desktop Documents Downloads Music Pictures Public Templates VideosYour output may differ. That is fine. These are entries in your home directory, not a sacred list Linux is required to preserve.
Now add two options:
ls -laAn option changes how a command behaves. Options are commonly introduced with a hyphen.
-lrequests the long format, including permissions, ownership, size, and timestamps.-aincludes entries whose names begin with a period.
Names beginning with a period are normally called hidden files. They are not encrypted or specially protected. Ordinary directory listings omit them to reduce clutter. Configuration files such as .bashrc often use this convention.
The first two entries in an ls -la listing are usually:
...A single period means the current directory. Two periods mean its parent directory: the directory one level above it.
Move between directories with cd
Section titled “Move between directories with cd”cd stands for change directory. Run:
cd DocumentspwdIf Documents exists in your home directory, pwd should now end with:
/home/student/DocumentsReturn to the parent directory:
cd ..pwdYou should be back in your home directory.
You can return home from anywhere by running cd with no argument:
cdpwdYou can also write cd ~. The shorter form is convenient; the explicit form makes the destination easier to see while learning.
Knowledge check
Question 1 of 2
Knowledge check complete
You answered all 2 questions correctly.
Absolute and relative paths
Section titled “Absolute and relative paths”An absolute path describes a location from the root directory. It begins with /:
/home/student/Documents/notes.txtA relative path describes a location from the current working directory:
Documents/notes.txtIf your current directory is /home/student, those paths identify the same file. If you move to /tmp, the relative path points to /tmp/Documents/notes.txt instead.
That is why relative paths are convenient and dangerous in equal measure. They are short, but their meaning depends on where you stand.
We can demonstrate this without changing any files:
cdrealpath Documentscd /tmprealpath DocumentsThe first command should resolve to the Documents directory in your home. The second may report that /tmp/Documents does not exist. The text Documents stayed the same; its starting location changed.
Build a disposable practice tree
Section titled “Build a disposable practice tree”Let’s create a small directory tree in your home directory. These are your files, created for this exercise, so changing them is safe.
cdmkdir -p underdunn-course/navigation/evidencecd underdunn-course/navigationpwdmkdir creates a directory. The -p option also creates missing parent directories, so the entire path can be built in one command.
Your working directory should now end with:
/underdunn-course/navigationCreate three empty practice files:
touch notes.txt "strange name.txt" .hidden-notelsls -latouch creates an empty file when that name does not already exist. Compare the two listings:
lsshould shownotes.txtandstrange name.txt.ls -lashould also show.hidden-note.
The quotation marks around "strange name.txt" tell the shell to treat the space as part of one name. Without the quotes, the shell sees two separate arguments: strange and name.txt.
You can also escape a space with a backslash:
ls strange\ name.txtQuoting the entire path is usually easier to read:
ls "strange name.txt"Inspect a name before trusting it
Section titled “Inspect a name before trusting it”Filenames are labels chosen by people and programs. A file named photo.jpg is not required to contain a JPEG image. Attackers, challenge authors, and confused coworkers are all capable of naming files badly.
Run:
file notes.txtfile /etc/os-releasefile examines identifying patterns in the contents. The empty practice file may be reported as:
notes.txt: empty/etc/os-release should be identified as text. This does not tell us everything in the file, but it is better evidence than the filename alone.
Now inspect metadata:
stat notes.txtstat reports information maintained by the filesystem, including size, timestamps, ownership, and permissions. Your exact values will differ, but the size should be zero because touch created an empty file.
Knowledge check
Question 1 of 2
Knowledge check complete
You answered all 2 questions correctly.
Five directories worth recognizing
Section titled “Five directories worth recognizing”You do not need to memorize the entire Linux filesystem today. You should recognize these locations when they appear:
| Directory | What belongs there |
|---|---|
/home |
Home directories for ordinary users |
/etc |
System-wide configuration |
/tmp |
Temporary files; contents may disappear |
/var |
Data that changes while the system runs, including many logs |
/proc |
A virtual view of processes and kernel information |
/proc is the unusual one. Many entries look like files but are generated by the kernel when read. They are an interface to current system state rather than ordinary data stored on disk.
Try:
file /proc/cpuinfostat /proc/cpuinfoThe results may look odd compared with a normal file. That oddness is evidence that /proc behaves differently, not evidence that the commands failed.
Inspect before acting
Section titled “Inspect before acting”You now know enough commands to build a useful habit:
pwdls -lafile targetstat targetThis is not a ritual that must be typed before every command. It is a short investigation sequence:
- Confirm your current location.
- List everything present, including hidden entries.
- Ask what the target’s contents resemble.
- Inspect its metadata.
We have deliberately not introduced commands for deleting or moving files yet. Guessing with destructive commands is an unnecessary way to discover that a relative path did not mean what you thought it meant.
What this gives us as researchers
Section titled “What this gives us as researchers”You can now orient yourself in an unfamiliar part of a Linux system without relying on the graphical file browser or trusting filenames. More importantly, you can explain what each command contributes:
pwdestablishes location.lsidentifies nearby entries.cdchanges the location from which relative paths are interpreted.fileprovides evidence about contents.statprovides evidence about filesystem metadata.
That is already a small research process: establish context, gather observations, and avoid making changes until the target makes sense.
Knowledge check
Question 1 of 3
Knowledge check complete
You answered all 3 questions correctly.
Next, the Filesystem Investigation Lab will ask you to use these commands on a directory tree you did not create.