Linux Tutorial / Navigate Directories with pwd, ls, cd, and tree
To navigate Linux directories, use pwd to check where you are, ls to inspect a directory, and cd to move. tree can show the hierarchy when you need a broader view. This lesson combines the four commands so you can see how absolute and relative paths affect each move.
Check your current working directory first
A relative path entered in a terminal is interpreted from the current working directory. Your prompt might show an abbreviated location or be customized, so use pwd when you need the exact path.
pwd
For example, if your account is named learner and you are in its home directory, the output might be:
/home/learner
The actual home path depends on account configuration. pwd does not change your location. If you entered a directory through a symbolic link, its logical path and physical path may differ. In Bash, pwd -P displays the physically resolved path.
Inspect a directory's contents
ls lists file and directory names. Without an argument, it lists the current directory; with a path, it lists that location. These commands inspect your current directory and then /etc:
ls ls /etc
The ls /etc output might contain names like these. This is an abbreviated illustration, not a complete listing; names and layout vary by system.
hosts passwd ssh
Names beginning with a dot are normally omitted from the default listing. Add -a to include hidden entries. Use -l to see details such as permissions, owner, size, and modification time.
ls -a ls -l /etc
The first character in an ls -l row indicates the file-system type: d commonly means a directory, - a regular file, and l a symbolic link. The file-types lesson explains the rest of the row. If you need details about a directory itself rather than its contents, use ls -ld path.
Move using absolute and relative paths
cd changes the working directory of the current shell. An absolute path such as /etc takes you to the same location regardless of where you start. Follow it with pwd to verify the result.
cd /etc pwd
The pwd output will normally be:
/etc
While you are in /etc, cd .. goes up to its parent, /. cd - returns to the previous working directory; Bash also prints the directory it returns to. Run the following commands in the same shell and in this order for the described result.
cd .. pwd cd - pwd
Here the first pwd prints /; cd - and the final pwd show /etc. If you have moved elsewhere in between, cd - will return to a different directory.
Running cd without an argument goes to your home directory. In Bash, cd ~ is another common way to reach it. Because a home directory is not necessarily under /home, confirm the result with pwd.
cd pwd
View the directory hierarchy
tree displays a hierarchy using branches and indentation. Where ls is useful for inspecting one directory, tree helps you see how directories fit together. Limit the depth at first to avoid a very long listing.
tree -d -L 1 /etc
Follow the branches in this abbreviated illustration to see which directories are immediately beneath /etc. Actual directory names and counts vary.
/etc ├── ssh └── systemd
-d displays only directories, and -L 1 limits the displayed depth to one level. If tree is not installed, you might see command not found. You can use ls for now and install tree later with your distribution's package manager. The remaining exercises do not require it.
Practice navigating paths
Follow these steps and predict the current directory before each pwd. It is fine if your /etc listing differs from the example; this exercise does not create or change files.
- Run
pwdto check your starting directory. - Run
cd /etc, then usepwdandlsto check your location and its contents. - Run
cd ..and usepwdto confirm that you are at/. - Use
cd -to return to/etc; finally, runcdto return home.
If you see cd: ...: No such file or directory, check the spelling and letter case of the path. Permission denied may mean that you lack permission to enter it. When unsure of your location, start again with pwd rather than guessing.
For more options and edge cases, read the individual guides to pwd, ls, cd, and tree.
Official documentation
See the GNU Bash built-ins documentation for cd and Bash's pwd, the GNU Coreutils ls documentation, and the tree(1) manual for the options used here.









