Working with Directories in
Linux
CHAPTER TWO
15/03/2026 CYBER SECURITY DEPARTMENT 1
Outlines
In this chapter, we will learn how to:
oDisplay the current directory
oMove between directories
oList directory contents
oCreate directories
oRemove directories
oUnderstand absolute and relative paths
15/03/2026 CYBER SECURITY DEPARTMENT 2
Introduction
In Linux, files are organized inside directories (also called folders). Directories
help users organize files in a structured way.
Linux uses a tree structure, where all directories start from the root directory.
The root directory is represented by:
/
Inside this directory, we can find many other directories such as /home, /etc,
/usr, and /var.
15/03/2026 CYBER SECURITY DEPARTMENT 3
Types of files in the Linux system
Linux categorizes files into different types based on their purpose, such as general data
storage, system structure, or device representation.
[Link] Files - It is also called ordinary files. It may be an image, video, program, or
simple text file. These types of files can be in ASCII or Binary format. It is the most
commonly used file in the Linux system.
[Link] Files - These types of files are a warehouse for other file types. It may be a
directory file within a directory (subdirectory).
[Link] Files - In a Windows-like operating system, devices like CD-ROM and hard
drives are represented as drive letters like F: G: H, whereas in the Linux system, devices
are represented as files. As for example, /dev/sda1, /dev/sda2, and so on.
15/03/2026 CYBER SECURITY DEPARTMENT 4
Types of files in the Linux system
We know that in a Windows-like operating system, files are stored in different
folders on different data drives like C: D: E:, whereas in the Linux/Unix operating
system, files are stored in a tree-like structure starting with the root directory.
The Linux/Unix file system hierarchy base begins at the root and everything
starts with the root directory.
15/03/2026 CYBER SECURITY DEPARTMENT 5
Top-level directories associated with the
root directory
These top-level directories under the root (/) form the foundation of the Linux file
system, each serving a specific role in organizing system files, user data, and
configurations.
• /bin - Contains essential binary or executable programs required for basic system
operation.
• /etc - Stores system-wide configuration files used to control system behavior.
• /home - Contains user home directories and serves as the default working
directory for users.
• /opt - Holds optional or third-party software packages installed separately from
the system.
• /tmp - Provides temporary storage space for files, which is typically cleared on
system reboot.
• /usr - Contains user-related programs, utilities, and shared resources.
• /var - Stores variable data such as log files that change frequently during system
operation.
15/03/2026 CYBER SECURITY DEPARTMENT 6
Display the current directory
The pwd command in Linux displays the full path of your current working directory
from the root directory. It helps users identify their present location within the
filesystem.
It helps users identify their exact location within the Linux file system hierarchy.
To print the current working directory, simply enter:
$pwd
Example:
──(kali@kali)-[~]
└─$ pwd
/home/kali
15/03/2026 CYBER SECURITY DEPARTMENT 7
Change Directory
The cd (change directory) command is used to change the current working directory in Linux and
other Unix-like operating systems. It is one of the most basic and frequently used commands
when working on the Linux terminal.
◦ To change directory, simply enter:
$cd /directory Name
──(kali@kali)-[~]
Example: └─$ pwd
/home/kali
┌──(kali@kali)-[~]
└─$ cd /etc
┌──(kali@kali)-[/etc]
└─$ pwd
/etc
15/03/2026 CYBER SECURITY DEPARTMENT 8
Navigate to the Home Directory
To navigate to your home directory, simply type cd. Another way to return directly to your home
directory is to use the tilde (~) character, as shown below:
$cd ~
──(kali@kali)-[~]
Example: └─$ pwd
/home/kali
┌──(kali@kali)-[~]
└─$ cd /etc
┌──(kali@kali)-[/etc]
└─$ pwd
/etc
┌──(kali@kali)-[/etc]
└─$ cd ~
┌──(kali@kali)-[~]
└─$ pwd
/home/kali
15/03/2026 CYBER SECURITY DEPARTMENT 9
Parent Directory
To go to the parent directory (the one just above your current directory in the
directory tree), type :
$cd ..
Example:
┌──(kali㉿kali)-[~]
└─$ pwd
/home/kali
┌──(kali㉿kali)-[~]
└─$ cd ..
┌──(kali㉿kali)-[/home]
└─$ pwd
/home
15/03/2026 CYBER SECURITY DEPARTMENT 10
Previous Directory
To change back to the previous working directory, pass the dash (-) character as an argument to
the cd command:
$cd –
Example:
┌──(kali@kali)-[/home]
└─$ pwd
/home
┌──(kali@kali)-[/home]
└─$ cd -
~
┌──(kali@kali)-[~]
└─$ pwd
/home/kali
15/03/2026 CYBER SECURITY DEPARTMENT 11
Listing Directories
To list directories, you can use this command:
$ls
Adding the -l option provides detailed information about each item, including whether it’s a file or
directory. In the detailed output, entries that start with a ‘d’ (e.g., drwxrwxr-x) indicate directories.
$ls -l
Adding the -a option with ls to show all files. Showing all files means including the hidden files. When
a file name on a Linux file system starts with a dot, it is considered a hidden file and it doesn't show
up in regular file listings.
$ls –a
Adding the lh (Human Readable Format) option When files are large, their sizes are displayed in
bytes.
$ls –lh
15/03/2026 CYBER SECURITY DEPARTMENT 12
Listing Directories
Note:
The following commands produce the same output because Linux treats the options -l and -h
the same regardless of their order.
• ls -l -h
• ls -h -l
• ls -lh
• ls -hl
All of them display files in long listing format (-l) with human-readable file sizes (-h) such as KB,
MB, or GB instead of bytes.
15/03/2026 CYBER SECURITY DEPARTMENT 13
Creating Directories
To create a directory in Linux you have to use mkdir command which stands for make
directory.
$mkdir directory_name
Example:
$ mkdir courses
15/03/2026 CYBER SECURITY DEPARTMENT 14
Example
──(kali@kali)-[~] ┌──(kali@kali)-[~]
└─$ mkdir courses └─$ ls -a
┌──(kali@kali)-[~] . .[Link] Downloads Music Videos
└─$ ls .. .cache .face Pictures .zprofile
alaa Desktop Downloads Music Public Videos alaa .config .[Link] .profile .zshrc
courses Documents kalifolder Pictures T .[Link] courses .java Public
──(kali@kali)-[~] .bash_logout Desktop kalifolder .[Link]
└─$ ls -l .bashrc Documents .local Templates
Total 44 ┌──(kali@kali)-[~]
drwxrwxr-x 2 kali kali 4096 Mar 13 15:29 alaa └─$ ls -lh
drwxrwxr-x 2 kali kali 4096 Mar 13 15:43 courses total 44K
drwxr-xr-x 2 kali kali 4096 Oct 23 08:22 Desktop drwxrwxr-x 2 kali kali 4.0K Mar 13 15:29 alaa
drwxr-xr-x 2 kali kali 4096 Oct 23 08:22 Documents drwxrwxr-x 2 kali kali 4.0K Mar 13 15:43 courses
drwxr-xr-x 2 kali kali 4096 Oct 23 08:22 Downloads drwxr-xr-x 2 kali kali 4.0K Oct 23 08:22 Desktop
drwxrwxr-x 2 kali kali 4096 Mar 13 15:35 kalifolder drwxr-xr-x 2 kali kali 4.0K Oct 23 08:22 Documents
drwxr-xr-x 2 kali kali 4096 Oct 23 08:22 Music drwxr-xr-x 2 kali kali 4.0K Oct 23 08:22 Downloads
drwxr-xr-x 2 kali kali 4096 Oct 23 08:22 Pictures drwxrwxr-x 2 kali kali 4.0K Mar 13 15:35 kalifolder
drwxr-xr-x 2 kali kali 4096 Oct 23 08:22 Public drwxr-xr-x 2 kali kali 4.0K Oct 23 08:22 Music
drwxr-xr-x 2 kali kali 4096 Oct 23 08:22 Templates drwxr-xr-x 2 kali kali 4.0K Oct 23 08:22 Pictures
drwxr-xr-x 2 kali kali 4096 Oct 23 08:22 Videos drwxr-xr-x 2 kali kali 4.0K Oct 23 08:22 Public
emplates drwxr-xr-x 2 kali kali 4.0K Oct 23 08:22 Templates
drwxr-xr-x 2 kali kali 4.0K Oct 23 08:22 Videos
15/03/2026 CYBER SECURITY DEPARTMENT 15
Removing Directories
When a directory is empty, you can use rmdir to remove the directory.
$rmdir directory_name
Example:
$rmdir courses
◦ However, this command works only if the directory is empty.
◦ If the directory contains files, the command will fail.
The -p option removes directories recursively if they are empty.
$ rmdir –p courses/test
15/03/2026 CYBER SECURITY DEPARTMENT 16
Absolute and Relative Path in Linux
In Linux, a path is used to specify the exact location of a file or directory inside the
filesystem. Since Linux follows a hierarchical directory structure starting from the root (/),
paths play a crucial role in file navigation, command execution, scripting, and system
administration.
Linux mainly uses two types of paths:
1. Absolute Path
2. Relative Path.
15/03/2026 CYBER SECURITY DEPARTMENT 17
Absolute Path
An absolute path is the complete and exact location of a file or directory starting from
the root directory (/). It clearly defines where a file exists in the filesystem, independent
of the user’s current directory.
• Always start with / in Linux/Unix.
• Independent of the current working directory.
• Best for: scripts, system configs where precision is critical.
15/03/2026 CYBER SECURITY DEPARTMENT 18
Changing Directory with Absolute path concept
Use an absolute path to navigate directly to a specific directory from the root, regardless
of your current location.
Example:
──(kali@kali)-[/home]
└─$ pwd
/home
┌──(kali@kali)-[/home]
└─$ cd /home/kali
┌──(kali@kali)-[~]
└─$ pwd
/home/kali
15/03/2026 CYBER SECURITY DEPARTMENT 19
Relative Paths
locate a file or directory in relation to the current working
directory.
• Do not start with /.
• Dependent on where you are in the filesystem.
• Use . for current directory and .. for parent directory.
• Best for: quick navigation, project-based work, portable scripts.
15/03/2026 CYBER SECURITY DEPARTMENT 20
Changing Directory with Relative path concept:
Use relative paths to navigate directories based on your current location in the file
system.
Example:
──(kali@kali)-[/home]
└─$ pwd
/home
┌──(kali@kali)-[/home]
└─$ cd kali
┌──(kali@kali)-[~]
└─$ pwd
/home/kali
15/03/2026 CYBER SECURITY DEPARTMENT 21
Conclusion
In this chapter, we learned how to work with directories in Linux. The main commands
introduced were (pwd, cd, ls, mkdir, rmdir).
Understanding these commands is essential because they allow users to navigate and organize
files in the Linux file system efficiently.
These skills are also important for system administration and cybersecurity tasks, where
professionals need to locate files, examine directories, and manage system resources.
15/03/2026 CYBER SECURITY DEPARTMENT 22