LearnAI ToolsCareerPractice BuildsPlayDevelopmentContact
Lesson 313 min read

Navigating the File System: pwd, ls and cd

Understand how Linux organises files in one tree, move around with cd, list files with ls, and use absolute and relative paths, ~, . and ..

On this page 11 sections

Introduction

In a graphical file manager you click folders to open them. On the command line you do the same thing with three commands: pwd tells you where you are, ls shows what is there, and cd moves you somewhere else. Master these and the rest of Linux becomes much easier.

What You Will Learn
  • How Linux arranges every file in a single tree starting at /.
  • How to find your location with pwd and list files with ls.
  • How to move around with cd, including ~, . and ..
  • The difference between absolute and relative paths.

One Big Tree

Windows has separate drives like C: and D:. Linux has a single tree that starts at the root folder, written /. Everything — your files, programs, settings and even other disks — lives somewhere below it. Folders are separated with forward slashes, so /home/priya/projects means: start at root, go into home, then priya, then projects.

Each user has a home folder, /home/<username>, where their own files live. It has a shortcut, the tilde ~. Priya has a small portfolio project in her home folder:

tree projects
Output

Click Run to see what this code prints.

(tree draws a folder as a diagram. If it is not installed, sudo apt install tree adds it — lesson 10.)

Where Am I? pwd

pwd prints the working directory — the folder your terminal is currently “in”. A new terminal starts in your home folder:

pwd
Output

Click Run to see what this code prints.

What Is Here? ls

ls
Output

Click Run to see what this code prints.

Files whose names begin with a dot are hidden; they usually hold settings. -a (all) shows them, along with . (this folder) and .. (the folder above):

ls -a
Output

Click Run to see what this code prints.

CommandShows
lsNames of files and folders
ls -aIncluding hidden files (names starting with .)
ls -lLong format: permissions, owner, size and date (lesson 6)
ls -lhLong format with readable sizes like 4.0K and 2.3M
ls -ltLong format, newest first
ls /etcThe contents of another folder, without moving there

Moving Around: cd

cd (change directory) moves you into a folder:

cd projects
pwd
ls
Output

Click Run to see what this code prints.

You can go several levels at once, and .. goes up one level:

cd projects/portfolio/css
cd ..
pwd
cd ../..
pwd
Output

Click Run to see what this code prints.

cd on its own (or cd ~) always takes you home, from anywhere, and cd - jumps back to the previous folder:

cd /etc
pwd
cd
pwd
Output

Click Run to see what this code prints.

Mini Challenge · Predict the Output

You are in /home/priya/projects/portfolio/css. You run cd ../images. Where are you now?

Choose one answer

Absolute and Relative Paths

KindStarts withExampleMeaning
Absolute//home/priya/projects/portfolioThe full address from the root — works from anywhere
RelativeA name, . or ..projects/portfolioStarts from your current folder
Home-relative~~/projects/portfolioStarts from your home folder — works from anywhere

From her home folder, all three of these list the same folder:

ls /home/priya/projects/portfolio
ls projects/portfolio
ls ~/projects/portfolio
Output

Click Run to see what this code prints.

Paths are case-sensitive, so a small typo fails:

cd Projects
Output

Click Run to see what this code prints.

Let Tab Type for You

Type cd pro and press Tab — the shell completes projects/. Tab completion avoids typos, and if nothing happens, it usually means the name you started does not exist.

Important System Folders

ls /
Output

Click Run to see what this code prints.

FolderWhat lives there
/homeUsers’ home folders
/rootThe root user’s home folder
/etcSystem-wide configuration files
/bin, /usr/binPrograms (commands like ls and cat)
/varData that changes: logs in /var/log, websites often in /var/www
/tmpTemporary files, cleared regularly
/mnt, /mediaWhere other disks and USB drives appear
/dev, /proc, /sysSpecial files that represent devices and the running system
Mini Challenge · Put It in Order

Put these folders in order to build the absolute path to Priya’s stylesheet, /home/priya/projects/portfolio/css.

  1. /
  2. css
  3. home
  4. projects
  5. portfolio
  6. priya

Common Mistakes

Avoid These Mistakes
  • Using backslashes (\) as in Windows — Linux paths use forward slashes (/).
  • Forgetting that projects and Projects are different names.
  • Typing cd /projects when you meant cd projects — the leading / means “from the root”.
  • Not quoting names with spaces: cd my folder fails; use cd "my folder" or Tab completion.

Frequently Asked Questions

Most terminals colour folders, programs and links differently to make listings easier to scan. The colours do not change anything; they are just a display aid.

Under /mnt/c for the C: drive, /mnt/d for D:, and so on. For example, your Windows Desktop is usually /mnt/c/Users/<name>/Desktop.

None — directory is the traditional Unix name, folder is the everyday name. You will see both.

Key Takeaways

  • Linux has one file tree starting at /; your files live under /home/<you>, shortened to ~.
  • pwd shows where you are, ls lists what is there, and cd moves you.
  • . is the current folder, .. the parent, cd alone goes home and cd - goes back.
  • Absolute paths start with /, relative paths start from where you are.
  • Names are case-sensitive — use Tab completion to avoid typos.

Summary

You can now find your way around any Linux system. Next you will start changing things: creating folders and files, copying, moving, renaming and deleting them.

Next Lesson →

Managing Files and Folders: mkdir, cp, mv and rm