Skip to content
UnderDunn Courses

Navigating the Linux Filesystem

Linux FoundationsLesson 2 of 745 minutesLab included

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.

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/student

The shell also uses a tilde as shorthand for your home directory:

~

The shell keeps track of a current working directory. This is the directory from which relative paths are interpreted.

Run:

Terminal window
pwd

pwd stands for print working directory. If your username is student, the output will probably resemble:

/home/student

The 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.

Run:

Terminal window
ls

ls lists directory contents. On Ubuntu Desktop, you may see names such as:

Desktop Documents Downloads Music Pictures Public Templates Videos

Your 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:

Terminal window
ls -la

An option changes how a command behaves. Options are commonly introduced with a hyphen.

  • -l requests the long format, including permissions, ownership, size, and timestamps.
  • -a includes 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.

cd stands for change directory. Run:

Terminal window
cd Documents
pwd

If Documents exists in your home directory, pwd should now end with:

/home/student/Documents

Return to the parent directory:

Terminal window
cd ..
pwd

You should be back in your home directory.

You can return home from anywhere by running cd with no argument:

Terminal window
cd
pwd

You 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

Which command directly reports your current working directory?

An absolute path describes a location from the root directory. It begins with /:

/home/student/Documents/notes.txt

A relative path describes a location from the current working directory:

Documents/notes.txt

If 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:

Terminal window
cd
realpath Documents
cd /tmp
realpath Documents

The 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.

Let’s create a small directory tree in your home directory. These are your files, created for this exercise, so changing them is safe.

Terminal window
cd
mkdir -p underdunn-course/navigation/evidence
cd underdunn-course/navigation
pwd

mkdir 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/navigation

Create three empty practice files:

Terminal window
touch notes.txt "strange name.txt" .hidden-note
ls
ls -la

touch creates an empty file when that name does not already exist. Compare the two listings:

  • ls should show notes.txt and strange name.txt.
  • ls -la should 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:

Terminal window
ls strange\ name.txt

Quoting the entire path is usually easier to read:

Terminal window
ls "strange name.txt"

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:

Terminal window
file notes.txt
file /etc/os-release

file 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:

Terminal window
stat notes.txt

stat 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

What makes /home/student/notes.txt an absolute path?

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:

Terminal window
file /proc/cpuinfo
stat /proc/cpuinfo

The results may look odd compared with a normal file. That oddness is evidence that /proc behaves differently, not evidence that the commands failed.

You now know enough commands to build a useful habit:

Terminal window
pwd
ls -la
file target
stat target

This is not a ritual that must be typed before every command. It is a short investigation sequence:

  1. Confirm your current location.
  2. List everything present, including hidden entries.
  3. Ask what the target’s contents resemble.
  4. 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.

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:

  • pwd establishes location.
  • ls identifies nearby entries.
  • cd changes the location from which relative paths are interpreted.
  • file provides evidence about contents.
  • stat provides 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

Your current directory is /home/student/projects/demo. What does ../notes.txt refer to?

Next, the Filesystem Investigation Lab will ask you to use these commands on a directory tree you did not create.