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.
- 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 projectsClick 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:
pwdClick Run to see what this code prints.
What Is Here? ls
lsClick 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 -aClick Run to see what this code prints.
| Command | Shows |
|---|---|
| ls | Names of files and folders |
| ls -a | Including hidden files (names starting with .) |
| ls -l | Long format: permissions, owner, size and date (lesson 6) |
| ls -lh | Long format with readable sizes like 4.0K and 2.3M |
| ls -lt | Long format, newest first |
| ls /etc | The contents of another folder, without moving there |
Moving Around: cd
cd (change directory) moves you into a folder:
cd projectspwdlsClick Run to see what this code prints.
You can go several levels at once, and .. goes up one level:
cd projects/portfolio/csscd ..pwdcd ../..pwdClick 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 /etcpwdcdpwdClick Run to see what this code prints.
You are in /home/priya/projects/portfolio/css. You run cd ../images. Where are you now?
Absolute and Relative Paths
| Kind | Starts with | Example | Meaning |
|---|---|---|---|
| Absolute | / | /home/priya/projects/portfolio | The full address from the root — works from anywhere |
| Relative | A name, . or .. | projects/portfolio | Starts from your current folder |
| Home-relative | ~ | ~/projects/portfolio | Starts from your home folder — works from anywhere |
From her home folder, all three of these list the same folder:
ls /home/priya/projects/portfoliols projects/portfoliols ~/projects/portfolioClick Run to see what this code prints.
Paths are case-sensitive, so a small typo fails:
cd ProjectsClick Run to see what this code prints.
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 /Click Run to see what this code prints.
| Folder | What lives there |
|---|---|
| /home | Users’ home folders |
| /root | The root user’s home folder |
| /etc | System-wide configuration files |
| /bin, /usr/bin | Programs (commands like ls and cat) |
| /var | Data that changes: logs in /var/log, websites often in /var/www |
| /tmp | Temporary files, cleared regularly |
| /mnt, /media | Where other disks and USB drives appear |
| /dev, /proc, /sys | Special files that represent devices and the running system |
Put these folders in order to build the absolute path to Priya’s stylesheet, /home/priya/projects/portfolio/css.
- /
- css
- home
- projects
- portfolio
- priya
Common 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.