Navigating and Managing Files in Kali

Kali LinuxKali LinuxBeginner
Practice Now

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.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL kali(("Kali")) -.-> kali/KaliGroup(["Kali"]) kali/KaliGroup -.-> kali/term_ops("Kali Terminal") kali/KaliGroup -.-> kali/file_ctrl("File Management") kali/KaliGroup -.-> kali/bash_code("Bash Scripting") subgraph Lab Skills kali/term_ops -.-> lab-552194{{"Navigating and Managing Files in Kali"}} kali/file_ctrl -.-> lab-552194{{"Navigating and Managing Files in Kali"}} kali/bash_code -.-> lab-552194{{"Navigating and Managing Files in Kali"}} end

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.

  1. 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.
Image showing Kali Linux container shell
  1. Confirm your current location in the file system by typing the following command and pressing Enter:

    pwd

    The output should be:

    /

    This means you are in the root directory, the topmost level of the Linux file system hierarchy. The pwd command stands for "print working directory" and is used to display your current location.

  2. Remain in the Kali Linux container shell for all subsequent steps. If you accidentally exit by typing exit or pressing Ctrl+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.

  1. Type the following command and press Enter to list the contents of the current directory, which is the root directory /:

    ls

    The 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  var

    These are standard directories in a Linux system. For example, bin contains executable files, and etc holds configuration files.

  2. To see more details about these directories, use the ls command with the -l option for a long format listing. Type the following command and press Enter:

    ls -l

    The 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 -l option helps you understand the properties of each item in the directory.

  3. 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.

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.

  1. Confirm your current location by typing the following command and pressing Enter:

    pwd

    The output should be:

    /

    This confirms you are in the root directory.

  2. Move to the /home directory by typing the following command and pressing Enter:

    cd /home

    The cd command changes your current working directory to the specified path, in this case, /home.

  3. Verify your new location by typing the following command and pressing Enter:

    pwd

    The output should be:

    /home
  4. List the contents of the /home directory to see what is there. Type the following command and press Enter:

    ls

    The output might be empty or show minimal content since the container starts with a basic setup.

  5. 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 /.

  6. Confirm your location again by typing the following command and pressing Enter:

    pwd

    The output should be:

    /
  7. 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.

  1. Confirm your current location by typing the following command and pressing Enter:

    pwd

    The output should be:

    /

    If you are not in the root directory, navigate there with cd /.

  2. Create a new directory named myproject in the root directory to organize your files. Type the following command and press Enter:

    mkdir /myproject

    There will be no output if the command executes successfully. This creates a directory at the path /myproject.

  3. Move into the /myproject directory by typing the following command and pressing Enter:

    cd /myproject
  4. Verify your location by typing the following command and pressing Enter:

    pwd

    The output should be:

    /myproject
  5. Create an empty text file named notes.txt in the /myproject directory using the touch command. Type the following command and press Enter:

    touch notes.txt

    There will be no output if successful. This creates an empty file at /myproject/notes.txt.

  6. Verify the file was created by listing the directory contents. Type the following command and press Enter:

    ls

    The output should show:

    notes.txt
  7. Since nano might not be pre-installed in the minimal Kali Linux container, install it first. Type the following commands to update the package list and install nano. Press Enter after each command:

    apt update
    apt install -y nano

    The first command apt update refreshes the package list, and the second command apt install -y nano installs the nano editor without prompting for confirmation. This might take a moment, and you will see installation progress in the terminal.

  8. Add content to notes.txt using the nano editor. Type the following command and press Enter:

    nano notes.txt
  9. Once nano opens, 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.

  10. Save the changes and exit nano by following these actions:

    • Press Ctrl + O to write the changes, then press Enter to confirm the file name.
    • Press Ctrl + X to exit the editor. You will return to the terminal.
  11. 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.

  1. Confirm your current location by typing the following command and pressing Enter:

    pwd

    The output should be:

    /myproject

    If you are not in /myproject, navigate there with:

    cd /myproject
  2. Verify that notes.txt exists by listing the directory contents. Type the following command and press Enter:

    ls

    The output should show:

    notes.txt
  3. Create a copy of notes.txt named notes_backup.txt in the same directory using the cp command. Type the following command and press Enter:

    cp notes.txt notes_backup.txt

    There will be no output if the command executes successfully. This duplicates notes.txt as notes_backup.txt in /myproject.

  4. Verify that the copy was created by listing the directory contents. Type the following command and press Enter:

    ls

    The output should show:

    notes.txt  notes_backup.txt
  5. Delete the copied file notes_backup.txt using the rm command. Type the following command and press Enter:

    rm notes_backup.txt

    There will be no output if the command executes successfully. This removes notes_backup.txt from /myproject.

  6. Verify that the file was deleted by listing the directory contents again. Type the following command and press Enter:

    ls

    The output should show:

    notes.txt
  7. Stay 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.

  1. Confirm your current location by typing the following command and pressing Enter:

    pwd

    The output should be:

    /myproject

    If you are not in /myproject, navigate there with:

    cd /myproject
  2. Verify that notes.txt exists by listing the directory contents. Type the following command and press Enter:

    ls

    The output should show:

    notes.txt
  3. View the contents of notes.txt using the cat command. Type the following command and press Enter:

    cat notes.txt

    The 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.

  4. You can stay in the container shell to explore further. If you wish to return to the LabEx VM terminal, type exit or press Ctrl+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.