Skip to content

Navigating the File System

💡
Before you start

You need a Linux machine, or any terminal on macOS — nothing is installed and nothing is bought. Every command on this page is read-only or works inside a practice folder you create and can delete afterwards, and none of them needs sudo. If you have never opened a terminal at all, start with Introduction to the Linux Terminal, which shows you where it is and how to get your bearings.

Where Am I? The pwd Command

When you open a terminal, you are always "standing" inside a directory on your file system. Before you start moving around, it helps to know exactly where you are. That is what pwd (print working directory) does.

pwd

The output will look something like:

/home/john

This tells you the full, absolute path of the directory you are currently in. On Linux, every user has a home directory located at /home/username. When you first open a terminal, this is where you start.

💡
Absolute vs. Relative Paths

An absolute path starts from the root of the file system (/) and describes the complete location, like /home/john/Documents. A relative path describes a location relative to where you currently are, like Documents (no leading slash). Both are valid ways to refer to files and directories.

Moving Around with cd

The cd (change directory) command is how you move from one directory to another. It is the most frequently used navigation command and the foundation of terminal workflow.

Basic Usage

To move into a directory, type cd followed by the directory name or path:

# Move into the Documents folder
cd Documents

# Verify you moved
pwd
/home/john/Documents

Going Up with ..

Two dots (..) represent the parent directory -- the directory one level above your current location. You can chain them together to go up multiple levels.

# Go up one level
cd ..

# Go up two levels
cd ../..

# Go up one level and into a sibling directory
cd ../Downloads

Handy cd Shortcuts

cd ~ Go to your home directory from anywhere. You can also just type cd with no arguments.
cd - Go back to the previous directory you were in. Very useful for toggling between two locations.
cd / Go to the root of the entire file system.
# Jump home from anywhere
cd ~

# Or simply
cd

# Toggle between two directories
cd /var/log
cd /etc/nginx
cd -
# You are now back in /var/log

Listing Files with ls

Once you have navigated to a directory, you need to see what is inside it. The ls command lists the contents of a directory.

Basic ls

ls

This shows the names of files and folders in your current directory. However, it hides files that start with a dot (hidden files) and does not show much detail.

Useful ls Flags

ls -l Long format. Shows permissions, owner, group, size, date, and name.
ls -a Show all files, including hidden ones (those starting with a dot).
ls -la Combine long format and show all. This is the most commonly used form.
ls -lh Long format with human-readable file sizes (KB, MB, GB instead of bytes).
ls -lt Long format sorted by modification time, newest first.
# List everything with details
ls -la

total 32
drwxr-xr-x  5 john john 4096 Mar  1 10:30 .
drwxr-xr-x  3 root root 4096 Feb 15 08:00 ..
-rw-------  1 john john 1200 Mar  1 09:15 .bash_history
-rw-r--r--  1 john john  220 Feb 15 08:00 .bashrc
drwxr-xr-x  2 john john 4096 Feb 20 14:00 Documents
drwxr-xr-x  2 john john 4096 Feb 22 11:30 Downloads
-rw-r--r--  1 john john  675 Feb 15 08:00 .profile

You can also list the contents of a specific directory without navigating into it:

# List contents of /etc without moving there
ls -l /etc

Tab Completion for Faster Navigation

One of the most powerful features of the Linux terminal is tab completion. Instead of typing out long directory or file names in full, you can type the first few characters and press Tab.

1
Type the beginning of a name: cd Doc
2
Press Tab -- the shell completes it to cd Documents/
3
If multiple matches exist, press Tab twice to see all options. Then type more characters to narrow it down.
💡
Tab completion prevents typos.

Get into the habit of using Tab after every few characters. It is faster than typing full names, and if nothing completes, it tells you the path does not exist -- catching mistakes before you run the command.

Understanding the Linux Directory Tree

Linux organizes everything into a single directory tree starting at the root (/). Unlike Windows which uses drive letters (C:\, D:\), Linux mounts everything under this one tree. Here are the most important directories you will encounter:

/ The root directory. Everything starts here.
/home Contains personal directories for each user. Your files live here.
/etc System configuration files. Most services are configured here.
/var Variable data like logs (/var/log) and web files (/var/www).
/tmp Temporary files. Cleared on reboot.
/usr User programs and utilities. Most installed software lives under /usr/bin.
⚠️
Stay out of system directories as a beginner.

Directories like /etc, /usr, and /var contain files that your system needs to run. Browse them freely with ls, but do not modify anything there unless you know what you are doing.

Now Do It Yourself: Five Steps

Moving around a filesystem confidently is the skill everything else on Linux rests on. You will build a small folder tree and then find your way around it without guessing. Nothing here needs sudo, and every output below is exactly what the terminal printed.

1
Build a tree to practise on

Go: open a terminal and type cd on its own to make sure you start at home.

Do: run these three commands.

mkdir -p practice/projects/web
cd practice
touch words.txt projects/web/index.html

You should see: no output from any of them. -p is what lets mkdir create practice, projects and web in one go — without it, it refuses to create a folder whose parent does not exist yet.

If not: mkdir: cannot create directory 'practice/projects/web': No such file or directory means you left out -p. That message names the deepest path it could not reach, which is a useful habit to notice: the error tells you where it stopped, not just that it failed.

2
Go down, and come back up

Go: you are in practice.

Do: run these four commands one at a time, reading each answer.

cd projects/web
pwd
cd ..
pwd

You should see: a path ending /practice/projects/web, then after cd .. a path ending /practice/projects. .. always means "the folder above this one", anywhere on the system. Chain it if you need to: cd ../.. goes up twice.

If not: cd: projects/web: No such file or directory usually means you are not where you think. Run pwd before blaming the path — a relative path like projects/web only works from the folder that contains projects.

3
See the difference between an absolute and a relative path

Go: you are now in practice/projects.

Do: run ls web/index.html, then run ls index.html. The second is meant to fail.

You should see: first web/index.html, then ls: cannot access 'index.html': No such file or directory. Same file, two paths — and only the one written relative to where you are standing works. A path starting with / or ~ is absolute and works from anywhere; anything else is measured from your current folder.

If not: if both succeed, you are in web rather than projects — check with pwd. This single distinction causes more beginner confusion than any other part of the terminal, which is why it is worth seeing fail once on purpose.

4
Look without moving, and see what is hidden

Go: run cd ~/practice to jump straight back, from wherever you are.

Do: run these three commands.

touch .hidden
ls
ls -a

You should see: ls shows projects and words.txt; ls -a shows those plus ., .. and .hidden. A leading dot in a name is the whole of what "hidden" means on Linux — there is no separate flag on the file. . is this folder and .. is the one above, which is why cd .. works.

If not: if .hidden shows up in plain ls, you named it hidden without the dot. Note also that ls projects/web lists that folder without moving you into it — most commands accept a path, so you often do not need to cd at all.

5
Find something when you do not know where it is

Go: stay in practice.

Do: run find . -name "*.txt", then run find . -type d.

You should see: first ./words.txt, then a list of the folders including ., ./projects and ./projects/web. find searches downwards from the folder you name — here ., meaning "from here" — and keeps going through every level beneath it.

If not: if it prints nothing, either nothing matches or you are somewhere unexpected. Keep the quotes around "*.txt": without them the shell expands the pattern itself before find ever sees it, and you get a confusing result that depends on what happens to be in the current folder.

🎉
Check yourself before moving on

Without scrolling up: a command works when you run it from one folder and fails from another, with the same path typed both times. Why? Answer: the path is relative, so it is measured from wherever you are standing. Make it absolute — start it with / or ~ — if it must work from anywhere.

Now do it without the page: from your home folder, and without using cd at all, list the contents of practice/projects/web and then find every .html file under practice. Steps 4 and 5, with the moving-around part removed.

Summary

In this tutorial, you learned the three core navigation commands:

  • pwd -- Print your current working directory
  • cd -- Change to a different directory (with shortcuts like ~, .., and -)
  • ls -- List directory contents (with flags like -la and -lh)
  • The difference between absolute and relative paths
  • How to use Tab completion to navigate faster
  • The basic layout of the Linux directory tree
🎉
Great progress!

You can now move around the Linux file system with confidence. In the next tutorial, you will learn how to create, copy, move, and delete files and directories.