In the previous chapter, you learned about the terminal, the shell, and the basic structure of Linux commands. Now it is time to put that knowledge into practice. This chapter covers the three most fundamental commands for exploring the filesystem from the terminal: pwd to know your location, ls to view directory contents, and cd to change directories. You will also learn the difference between absolute and relative paths, the meaning of the . and .. symbols, and the tree command to visually display the directory structure. Mastering this navigation is a mandatory prerequisite before moving on to more complex commands.
pwd: Viewing the Current Directory
When working in the terminal, you are always "inside" a directory. This directory is called the current working directory. All relative paths you type are resolved from this location, so it is important to always know where you are.
The pwd command (short for print working directory) displays the full path of the directory you are currently in. Run this command:
pwdIf you have just opened a terminal, the result will most likely be your home directory, e.g. /home/username. With pwd, you will never get lost while exploring the Linux directory tree.
ls: Viewing Directory Contents
ls (short for list) is the command to display the contents of a directory. Without additional arguments, ls shows the contents of the current directory:
lsThis command displays a list of file names and subdirectories in a simple format. However, ls becomes much more useful when combined with its options. The three most frequently used options are:
ls -l: Long Format
The -l (long) option displays detailed information for each file and directory, such as permissions, owner, size, and modification time:
ls -lThe output shows one line per entry, e.g. drwxr-xr-x 2 user user 4096 Jan 1 09:00 Documents. Briefly, the column order is: file type and permissions, number of hard links, owner, group, size in bytes, last modification date, and then the file or directory name. Detailed explanation of permission bits (rwx) will be covered in depth in the chapter on file permissions.
ls -a: Showing Hidden Files
By default, ls does not show hidden files, i.e. files whose names begin with a dot (dotfiles). The -a (all) option shows all entries, including hidden files:
ls -aAfter running this command, you will see entries like .bashrc and .config that were previously invisible.
ls -lh: Human‑Readable Sizes
The -h (human‑readable) option makes file sizes appear in easy‑to‑read units such as KB, MB, or GB. This option is usually combined with -l:
ls -lhYou can also combine several options at once, e.g. ls -la to display all files including hidden ones in long format. The ls command also accepts a directory name as an argument, e.g. ls /etc to display the contents of the /etc directory.
Colours in ls Output
Both Ubuntu 26.04 LTS and Fedora Workstation 44 enable colour syntax highlighting by default for ls (via the --color=auto option already set in the default shell configuration). These colours help you recognise entry types at a glance without needing to run ls -l:
- Blue: directory.
- White or default text colour: regular file.
- Green: executable file.
- Cyan: symbolic link.
- Yellow with black background (depending on the terminal colour scheme): device files in
/dev.
The exact colour scheme may vary slightly depending on the terminal theme and the dircolors settings used, but the basic pattern is consistent across both distributions. If you ever want to see the colour‑free version, for example when piping ls output to another command, use ls --color=never.
cd: Changing Directories
cd (short for change directory) is the command to move from one directory to another. Its usage is simple: type cd followed by the destination path:
cd /home/username/DocumentsAfter executing this command, your current working directory changes to /home/username/Documents. You can verify this with the pwd command.
Absolute vs Relative Paths
When specifying the destination directory with cd, you have two ways: using an absolute path or a relative path.
An absolute path is a path written in full from the root directory /, e.g. /home/username/Documents. An absolute path always starts with a slash and points to the same location regardless of your current position.
A relative path is a path computed from your current working directory. If you are in /home/username and want to move to /home/username/Documents, you can simply type:
cd DocumentsThis command means "move to the Documents directory that is inside the current directory". Relative paths are shorter to type, but they are only correct if you are already in the right place.
. and .. : Special Directories
There are two special entries that exist in every directory and are very important for navigation:
.(single dot) refers to the current directory. Typingcd .does not change your position, because you are "moving" to the same directory...(double dot) refers to the parent directory, i.e. one level above the current directory.
To go up one level, use:
cd ..You can combine them to go up several levels at once, e.g. cd ../.. to go up two levels. This concept makes it easy to move up and down the directory hierarchy without typing the full path.
cd ~ and cd -
In addition to . and .., there are two other very useful shortcuts:
cd ~takes you to your home directory. The tilde~is a shorthand for your home directory, socd ~is equivalent tocd /home/username. In fact, typing justcdwithout any arguments also takes you home.cd -takes you back to the previous directory. This is very practical when you have moved from one directory to another and want to return to the original one.
cd ~
cd -With the combination of cd ~, cd -, cd .., and absolute and relative paths, you can quickly move anywhere in the filesystem.
Handling Directory Names with Spaces
As mentioned in Chapter 11, file and directory names in Linux may contain spaces, e.g. Team Meeting. However, the shell uses spaces as argument separators, so typing cd Team Meeting would be interpreted as two separate arguments and produce an error. There are two common ways to handle this:
- Using quotes, e.g.
cd "Team Meeting"orcd 'Team Meeting'. - Using the escape character
\before the space, e.g.cd Team\ Meeting.
The easiest way to avoid this issue entirely is to type part of the directory name and press Tab to use tab completion (covered in Chapter 14). The shell will automatically add the necessary escapes.
tree: Displaying Directory Structure
The ls command only shows the contents of one directory at a time. To see the directory structure including all its subdirectories in a hierarchical view, you can use the tree command:
treeThis command displays the current directory as a tree diagram, complete with all subdirectories inside it. tree is very helpful for understanding the relationships between directories at a glance.
Note that tree is not always installed by default on either Ubuntu or Fedora. If the command is not found, you can install it first:
sudo apt install tree # on Ubuntu
sudo dnf install tree # on FedoraOnce installed, the following options make tree even more practical for daily use:
tree -L 2: limits the display depth to 2 levels, useful for preventing overly long output in directories with many subdirectories.tree -d: shows only directories, omitting files, which is perfect for viewing just the folder structure skeleton.tree -a: includes hidden files and directories (dotfiles) in the display, similar tols -a.
Be careful when running tree in your home directory without any depth limit, because directories like .config, .cache, and other application directories often contain thousands of files, making the output extremely long and hard to read. The combination tree -L 2 is usually sufficient for everyday needs.
Command Summary
The following table summarises all the navigation commands and options covered in this chapter, as a quick reference:
| Command | Function |
|---|---|
pwd | Display the current working directory |
ls | List the contents of the current directory |
ls -l | List contents in long format (permissions, owner, size, date) |
ls -a | List all entries, including hidden files |
ls -lh | Long format with human‑readable sizes (KB/MB/GB) |
cd <path> | Change to the target directory (absolute or relative path) |
cd .. | Go up one level to the parent directory |
cd ~ | Go back to the home directory |
cd - | Return to the previous directory |
tree | Display the directory structure as a tree diagram |
In this chapter, you have learned the three core commands for filesystem navigation: pwd to view the current directory, ls along with its options -l, -a, and -lh to list directory contents, and cd to change directories. You have also understood the difference between absolute and relative paths, the meaning of the . and .. symbols, the shortcuts cd ~ and cd -, how to handle directory names with spaces, and the use of tree with its practical options to display the directory structure.
In the next chapter, you will go further by learning how to create, copy, move, and delete files and directories using commands such as touch, mkdir, cp, mv, and rm.

