Navigating the Filesystem
Move through directories with cd, understand absolute vs relative paths, and use ls flags to see more detail.
- Use cd to move between directories
- Explain the difference between absolute and relative paths
- Use . and .. to navigate relative to the current directory
- Use ~ to return home from anywhere
- Use ls flags to see hidden files and detailed metadata
After hello-shell you know where you are (pwd) and what's around you (ls). Now let's move. Navigating the filesystem is the skill that makes everything else in the shell practical — you need to be in the right place to run most commands.
Absolute vs relative paths
Every file and directory on your computer has a path — a string that describes where it lives. Paths come in two flavors.
An absolute path starts from the root of the filesystem. On Linux and macOS, that root is /:
/home/alice/projects/my-app
/usr/local/bin/python3A relative path starts from wherever you currently are. If you're in /home/alice, then:
projects/my-app # same as /home/alice/projects/my-app
../bob/documents # go up one level, then into bob/documentsThe shell knows the difference: anything starting with / is absolute; anything else is relative.
Why does this matter? Scripts and configuration files that use absolute paths work from anywhere but break when you move files. Relative paths are portable within a project but depend on where you run them from. Both have their place — knowing the difference lets you choose deliberately.
cd — change directory
cd is the most-used navigation command. Give it a path and the shell moves there:
cd /tmp # absolute — go to /tmp from anywhere
cd projects # relative — go into the projects folder inside the current directory
cd .. # go up one level (the parent directory)
cd ../.. # go up two levels
cd ~ # go to your home directory from anywhere
cd - # go back to the previous directory (very handy)After each cd, run pwd to confirm where you ended up. That feedback loop — move, verify — is a good habit that prevents many "but I thought I was in…" mistakes.
. and ..
These two special entries exist in every directory:
.refers to the current directory itself. You'll see it used in commands likecp file.txt .(copy a file to the current location)...refers to the parent directory.cd ..goes up one level.
pwd # /home/alice/projects
cd .. # now in /home/alice
cd .. # now in /home
ls . # lists files in the current directory (same as ls)
ls .. # lists files in the parent directory~ and the home directory
Your home directory is your personal workspace — it's where your documents, configuration files, and projects typically live. The tilde ~ is a shortcut for it:
cd ~ # go home
cd ~/projects # go directly to ~/projects from anywhere
echo ~ # prints the full path of your home directory, e.g. /home/aliceThe shell expands ~ before running the command, so ~/projects becomes /home/alice/projects (or wherever your home is). This expansion happens reliably — you can always trust ~ to mean "home."
ls flags
ls on its own shows file and directory names. Flags unlock more detail, including file permissions:
ls -l # long format: permissions, owner, size, date, name
ls -a # all files, including hidden ones (names starting with .)
ls -la # combine both: long format plus hidden files
ls -lh # long format with human-readable sizes (1.2K instead of 1234)
ls /tmp # list a specific directory without cd-ing there firstHidden files (.bashrc, .gitignore, .env) are everywhere in developer work. They're hidden only from the default ls view — use ls -a whenever you suspect something is missing.
Tab completion: The shell can complete paths for you. Type the first few letters of a directory name and press Tab. If there's only one match, the shell completes it. If there are multiple, press Tab again to see them listed. This is faster than typing and catches typos before they become errors. It works for commands, flags, and file paths.
Check your understanding
- 1.Which of the following is an absolute path?
- 2.You are in /home/alice/projects. What directory are you in after running cd ../..?
- 3.Running ls without any flags will show files whose names start with a dot (.).
Do it yourself
Try this sequence in your terminal:
cd ~ # start from home
pwd # confirm where you are
ls -la # see everything including hidden files
cd /tmp # jump to an absolute path
pwd
cd - # jump back to where you were
pwd # you should be back in ~Then navigate into one of your project directories using a mix of cd with relative paths and tab completion. Get comfortable with cd .. to back up and cd - to return.
Where to go next
You can now move anywhere in the filesystem confidently. Next: files and directories — creating, copying, moving, and deleting files and folders with touch, mkdir, cp, mv, and rm.