Introduction
In this lab, you will learn the basics of navigating and managing files in Kali Linux, a powerful operating system widely used for cybersecurity and penetration testing. Through hands-on exercises, you will become familiar with essential Linux commands such as pwd, ls, cd, touch, nano, cp, rm, and cat. This lab provides step-by-step guidance to help you build a strong foundation for file and directory operations in a Linux environment. All activities will be performed inside a Kali Linux Docker container, which is automatically set up for you. When you open the terminal, you will be directly connected to the container's shell, ready to start practicing.
Getting Started in Kali Linux Container
In this first step, you will familiarize yourself with the Kali Linux container environment where all your practice will take place. The container has been automatically set up for you in the LabEx VM. When you open the terminal, you will be directly connected to the Kali Linux container's shell, so there is no need to manually start or attach to it.
Let's understand a basic concept for beginners. Kali Linux is a specialized Linux distribution designed for cybersecurity tasks, packed with tools for penetration testing. Running it in a Docker container provides an isolated, lightweight environment for learning without affecting the host system. The terminal you are using is your gateway to interact with this environment using commands.
Follow these steps to confirm you are in the correct environment.
- Open the terminal in the LabEx VM environment. You can do this by clicking the terminal icon on the Xfce desktop or using the terminal provided in the LabEx interface. Upon opening, you will see a welcome message indicating you are in the Kali Linux container shell. The prompt will likely appear as
root@xxxxxxxxxxxx:/#, showing you are logged in as the root user inside the container.

Confirm your current location in the file system by typing the following command and pressing Enter:
pwdThe output should be:
/This means you are in the root directory, the topmost level of the Linux file system hierarchy. The
pwdcommand stands for "print working directory" and is used to display your current location.Remain in the Kali Linux container shell for all subsequent steps. If you accidentally exit by typing
exitor pressingCtrl+D, simply reopen the terminal in the LabEx VM, and you will automatically reconnect to the container.
You have now confirmed your starting point in the Kali Linux container. In the next step, you will explore the contents of your current directory.
Exploring Directory Contents with ls
In this step, you will learn how to view the contents of a directory using the ls command inside the Kali Linux container. This command is essential for understanding what files and folders are present in your current location before performing any operations.
Let's break down a key concept for beginners. In Linux, the file system is organized as a tree structure with directories containing files and other directories. The ls command lists the contents of a directory, helping you see what is available. You can use options with ls to get more detailed information about the items listed.
Since you are already in the Kali Linux container shell, follow these steps to explore the root directory.
Type the following command and press Enter to list the contents of the current directory, which is the root directory
/:lsThe output will look similar to:
bin boot dev etc home lib lib32 lib64 libx32 media mnt opt proc root run sbin srv sys tmp usr varThese are standard directories in a Linux system. For example,
bincontains executable files, andetcholds configuration files.To see more details about these directories, use the
lscommand with the-loption for a long format listing. Type the following command and press Enter:ls -lThe output will show additional information like permissions, owner, size, and modification date, similar to:
total 72 drwxr-xr-x 2 root root 4096 Oct 10 10:00 bin drwxr-xr-x 2 root root 4096 Oct 10 10:00 boot drwxr-xr-x 13 root root 4096 Oct 10 10:00 dev drwxr-xr-x 85 root root 4096 Oct 10 10:00 etc ...The
-loption helps you understand the properties of each item in the directory.Stay in the container shell for the next steps. Do not exit the terminal.
You have successfully used the ls command to explore the contents of the root directory. In the next step, you will learn how to navigate between directories.
Navigating Directories with cd
In this step, you will learn how to move between directories in the Kali Linux container using the cd command. This command, which stands for "change directory," allows you to navigate the file system to access different locations, a critical skill for working in Linux.
Let's explain a fundamental concept for beginners. The Linux file system is like a tree, with the root directory / at the top and other directories branching out. Navigating with cd lets you move to specific locations where files or tools are stored. You can specify a full path like /home or use shortcuts like .. to move up one level to the parent directory.
Since you are in the Kali Linux container shell, follow these steps to practice navigation.
Confirm your current location by typing the following command and pressing Enter:
pwdThe output should be:
/This confirms you are in the root directory.
Move to the
/homedirectory by typing the following command and pressing Enter:cd /homeThe
cdcommand changes your current working directory to the specified path, in this case,/home.Verify your new location by typing the following command and pressing Enter:
pwdThe output should be:
/homeList the contents of the
/homedirectory to see what is there. Type the following command and press Enter:lsThe output might be empty or show minimal content since the container starts with a basic setup.
Move back to the root directory using the
..shortcut. Type the following command and press Enter:cd ..This moves you up one level to the parent directory, which is
/.Confirm your location again by typing the following command and pressing Enter:
pwdThe output should be:
/Stay in the container shell for the next steps. Do not exit the terminal.
You have now learned how to navigate directories using the cd command. In the next step, you will create a working directory and files to practice file management.
Creating and Editing Files with mkdir, touch, and nano
In this step, you will learn how to create directories and files, and edit text files in the Kali Linux container using the mkdir, touch, and nano commands. These are essential skills for organizing and managing data in Linux.
Let's cover some basic concepts for beginners. A directory is like a folder that can hold files and other directories, created using mkdir (make directory). The touch command creates an empty file, useful for placeholders or quick file creation. The nano command opens a simple text editor in the terminal, allowing you to add or modify content in files. These tools are fundamental for many tasks in Linux.
Follow these steps to create a directory and a file in the Kali Linux container shell.
Confirm your current location by typing the following command and pressing Enter:
pwdThe output should be:
/If you are not in the root directory, navigate there with
cd /.Create a new directory named
myprojectin the root directory to organize your files. Type the following command and press Enter:mkdir /myprojectThere will be no output if the command executes successfully. This creates a directory at the path
/myproject.Move into the
/myprojectdirectory by typing the following command and pressing Enter:cd /myprojectVerify your location by typing the following command and pressing Enter:
pwdThe output should be:
/myprojectCreate an empty text file named
notes.txtin the/myprojectdirectory using thetouchcommand. Type the following command and press Enter:touch notes.txtThere will be no output if successful. This creates an empty file at
/myproject/notes.txt.Verify the file was created by listing the directory contents. Type the following command and press Enter:
lsThe output should show:
notes.txtSince
nanomight not be pre-installed in the minimal Kali Linux container, install it first. Type the following commands to update the package list and installnano. Press Enter after each command:apt update apt install -y nanoThe first command
apt updaterefreshes the package list, and the second commandapt install -y nanoinstalls thenanoeditor without prompting for confirmation. This might take a moment, and you will see installation progress in the terminal.Add content to
notes.txtusing thenanoeditor. Type the following command and press Enter:nano notes.txtOnce
nanoopens, you will see a blank screen with a menu at the bottom. Type the following text:Learning file management in Kali Linux.Use the arrow keys to move the cursor if needed.
Save the changes and exit
nanoby following these actions:- Press
Ctrl + Oto write the changes, then press Enter to confirm the file name. - Press
Ctrl + Xto exit the editor. You will return to the terminal.
- Press
Stay in the container shell for the next steps. Do not exit the terminal.
You have successfully created a directory and a file, and edited content using mkdir, touch, and nano. In the next step, you will learn to copy and delete files.
Copying and Deleting Files with cp and rm
In this step, you will learn how to copy and delete files in the Kali Linux container using the cp and rm commands. These operations are crucial for managing files, such as creating backups or cleaning up unnecessary data.
Let's explain these concepts for beginners. The cp command, short for "copy," duplicates files or directories to another location or under a different name. The rm command, short for "remove," deletes files or directories. Be careful with rm as it permanently deletes items without a recycle bin or easy recovery option in Linux.
Since you are in the Kali Linux container shell, follow these steps to practice in the /myproject directory.
Confirm your current location by typing the following command and pressing Enter:
pwdThe output should be:
/myprojectIf you are not in
/myproject, navigate there with:cd /myprojectVerify that
notes.txtexists by listing the directory contents. Type the following command and press Enter:lsThe output should show:
notes.txtCreate a copy of
notes.txtnamednotes_backup.txtin the same directory using thecpcommand. Type the following command and press Enter:cp notes.txt notes_backup.txtThere will be no output if the command executes successfully. This duplicates
notes.txtasnotes_backup.txtin/myproject.Verify that the copy was created by listing the directory contents. Type the following command and press Enter:
lsThe output should show:
notes.txt notes_backup.txtDelete the copied file
notes_backup.txtusing thermcommand. Type the following command and press Enter:rm notes_backup.txtThere will be no output if the command executes successfully. This removes
notes_backup.txtfrom/myproject.Verify that the file was deleted by listing the directory contents again. Type the following command and press Enter:
lsThe output should show:
notes.txtStay in the container shell for the next step. Do not exit the terminal.
You have now learned how to copy and delete files using cp and rm. In the final step, you will learn to view file contents without opening them in an editor.
Viewing File Contents with cat
In this final step, you will learn how to view the contents of a file in the Kali Linux container using the cat command. This is a quick way to display file content directly in the terminal without opening it in an editor.
Let's clarify this concept for beginners. The cat command, short for "concatenate," is used to display the entire content of a file in the terminal. Unlike an editor like nano, which allows editing, cat provides a read-only view, making it ideal for quickly checking small files or scripts.
Since you are in the Kali Linux container shell, follow these steps to view the content of the file in /myproject.
Confirm your current location by typing the following command and pressing Enter:
pwdThe output should be:
/myprojectIf you are not in
/myproject, navigate there with:cd /myprojectVerify that
notes.txtexists by listing the directory contents. Type the following command and press Enter:lsThe output should show:
notes.txtView the contents of
notes.txtusing thecatcommand. Type the following command and press Enter:cat notes.txtThe output should display the content of the file, similar to:
Learning file management in Kali Linux.If the file is empty or does not exist, you will see no output or an error message.
You can stay in the container shell to explore further. If you wish to return to the LabEx VM terminal, type
exitor pressCtrl+D. Reopening the terminal will automatically reconnect you to the container.
You have completed the basic file and directory management tasks in this lab by learning to view file contents with cat.
Summary
In this lab, you have learned the fundamental skills of navigating and managing files in Kali Linux within a Docker container. You started by familiarizing yourself with the container environment, automatically accessed through the terminal. You explored essential commands like pwd to check your location, ls to list directory contents, and cd to navigate directories. Additionally, you practiced creating directories and files with mkdir and touch, editing content with nano, copying and deleting files with cp and rm, and viewing file contents with cat. These skills form a solid foundation for file and directory operations in a Linux environment, crucial for cybersecurity tasks in Kali Linux.


