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:
pwd
The output should be:
/
If you are not in the root directory, navigate there with cd /
.
-
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
.
-
Move into the /myproject
directory by typing the following command and pressing Enter:
cd /myproject
-
Verify your location by typing the following command and pressing Enter:
pwd
The output should be:
/myproject
-
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
.
-
Verify the file was created by listing the directory contents. Type the following command and press Enter:
ls
The output should show:
notes.txt
-
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.
-
Add content to notes.txt
using the nano
editor. Type the following command and press Enter:
nano notes.txt
-
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.
-
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.
-
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.