KALI LINUX 101: MODIFICATION OF FILES AND DIRECTORIES

KALI LINUX 101: MODIFICATION OF FILES AND DIRECTORIES


As promised, this article delves into modifying Linux files and directories—covering everything from creating files and directories or folders, renaming files, copying files, and removing files and directories, etc.


Hello, Goal-Setters!

This newsletter edition is an update on my "KALI LINUX 101: A BEGINNER'S GUIDE" series. In case you missed it, you can find the first part by clicking this Link Here: https://www.dhirubhai.net/pulse/kali-linux-101-beginners-guide-elizabeth-ekedoro-ctkcf?utm_source=share&utm_medium=member_android&utm_campaign=share_via


The Modification of Linux files and directories is important because it allows for personalization, system configuration, software management, file manipulation, collaboration, development, etc. It also empowers users with greater control, flexibility, and the ability to customize their Linux environment to best suit their preferences or needs and enhance?productivity.


MODIFICATION OF FILES AND DIRECTORIES

If you're already familiar with the basics, this guide will walk you through performing actions on your files and directories.

- This is our Desktop:

This is what our Desktop looks like before we go on to create more files.

- This is our Terminal:

Terminal.

- Before you start creating files, ensure you're in the right directory. For this guide, we'll be using the Desktop.

Desktop Directory.

FILES CREATION

We're going to be using two easy methods to create files in Kali Linux. The first is "touch" and the second is "cat" which stands for concatenate (this is used for joining the contents of several files together and printing the result in the terminal).

1. File creation with "touch"

- touch: This simple command instantly creates an empty file. For example, to create a file named "SOC.html" (you can choose any name you desire).

Run the command: touch SOC.html

- Use the ls command to verify its creation.

Our new "SOC.html" file has been created as seen in this image.

- look at our Desktop on the GUI and you can see the newly created "SOC.html" file.

The newly created 'SOC.html' file on our GUI.

2. File creation with "cat"

- cat: This command has other uses but for this guide, we'll be covering only two uses of cat.

- The first use of cat: this command is typically used for viewing files but we'll be using it to create files by adding the redirection symbol ">". To create a file

Run the command: cat > SOCAnalyst

I used the cat command, followed by a redirect ">"symbol and the file name of my choice which is "SOCAnalyst".

We can see the newly created 'SOCAnalyst' file on our Desktop.

The newly created "SOCAnalyst" file on our GUI.

Note: After running the command and pressing Enter, Linux enters interactive mode, allowing input for the file content. In my case, I inputted: "My name is Elizabeth Ekedoro, and I love Cybersecurity. It's a great day to practice and master your Linux skills". (see image below).

Interactive mode (you can go on to write anything you wish to).

Since the cat command is used to display the content of a file, to view what I had inputed in the above image I ran the command:

cat SOCAnalyst

You can see the result in this image (Note: I did not use the redirect ">" symbol in my command to view this.

Alternatively, you can click and open the ''SOCAnalyst'' file directly from your GUI to view its content.

View the "SOCAnalyst" file using the GUI.


- The second use of cat: is to write more data to the end of a pre-existing file (append) by using the double redirection symbol (">>").

To add more text to our 'SOCAnalyst' file we'll run the command;

cat >> SOCAnalyst

- After pressing Enter, Linux will go into interactive mode once again, enabling the appending of text. In my case, I appended: "It is important to stay Cyberaware to help protect yourself from Cyberattacks" as seen in the image below.

Appending with the command: cat >> SOCAnalyst.

- Upon checking the 'SOCAnalyst' file again by opening it from the desktop in our GUI, a warning may be displayed. Click "Reload"

If you get this warning just click 'Reload'.

and the newly added text will be visible, as shown in the image below.

You can now see the newly appended text.


CREATING A DIRECTORY

- make directory (mkdir): This is used to create a new directory or folder.

In this instance, I wanted to create a folder named "Cybersecurity" so I ran the command:

mkdir Cybersecurity

The "Cybersecurity" folder is now visible on our Desktop (the last folder in this image).

- Optionally, you can navigate into the newly created folder by running the command:

cd Cybersecurity

We're now in the newly created ''Cybersecurity'' Folder.


COPYING A FILE

- copy (cp): This command is used to duplicate a file from one location to another while keeping the original file intact.

Following the file creation method mentioned earlier using the touch command, I created a new file named "KaliLinux"

The newly created file is named "KaliLinux".

If you aren't sure of the file path, use pwd (present working directory) command.

Now that we have confirmed the file path (home/Lizettle/Desktop) as seen in the image below, copy the new file named "KaliLinux" into the "Cybersecurity" folder by running the command:

cp KaliLinux home/Lizettle/Desktop/Cybersecrutiy

cp KaliLinux home/Lizettle/Desktop/Cybersecurity.

If you navigate to the "Cybersecurity" directory or folder and run the command: ls you'll see the newly copied file was successfully duplicated.

We can now see our newly copied "KaliLinux" file in the image above.

Alternatively, you can open the "Cybersecurity" folder from your GUI and you'll find the "KaliLinux" file

Our newly copied "KaliLinux" file from our Desktop as seen in this image above


RENAMING A FILE

- move (mv): This serves a dual purpose. Firstly, it is used to relocate or move files from one location to another (unlike copy, move takes the file out and removes the original file), secondly, it is used to rename files.

To rename the existing from "KaliLinux" to "KaliLinuxPro"

Run the Command: mv KaliLinux KaliLinuxPro

Run the ls command, you'll observe the name changed from "KaliLinux" to "KaliLinuxPro"

Alternatively, you can confirm the successful renaming by checking the "Cybersecurity" folder using the GUI. The file, once known as "KaliLinux" will now be "KaliLinuxPro" as seen in the image below.


REMOVING A FILE

- Remove (rm): This is used to delete files within the Kali Linux command line interface (CLI).

In the image below, we'll be removing the "SOC.html" file.

To do this, run the command: rm SOC.html

Run the ls command, you'll notice that the "SOC.html" file is no longer listed, confirming its deletion.

Alternatively, we can check the Desktop on our GUI and you'll see the "SOC.html" file is absent. In other words, the file has been successfully removed or deleted.

The "SOC.html" file has been successfully deleted.


REMOVING A FOLDER OR DIRECTORY

- Remove directory (rmdir): This is used to delete folders or directories.

To illustrate this, I created a new folder on the Desktop which is named "PracticeKali" and that's the folder we would be removing/deleting.

To do this run the command: rmdir PracticeKali

Run the l or ls command, you'll notice that the "PracticeKali" folder is no longer listed, confirming its deletion.

Alternatively, we can check on our GUI and you'll see the "PracticeKali" folder is absent. In other words, the folder has been successfully removed or deleted.

The "PracticeKali" folder has been permanently deleted.


NOTE OF CAUTION

Unlike Windows, Linux does not prompt for permissions when deleting a file. It assumes that you know what you're doing. If you mistakenly delete the wrong file, be aware that it is permanently gone. Exercise extra caution when using the "rm" command, as it has the potential to delete everything on the file system.


CONCLUSION

With the knowledge gained from both this article and the previous one, you've acquired essential skills for navigating your Linux File System and modifying files and directories. Remember that additional resources are available online to further enhance your understanding. Consistent practice is the key to mastery, so ensure you practice regularly.


Feel free to reach out to me anytime for assistance and you can also connect with me on the following social platforms:

- X (Tweeter): https://x.com/Lizettle_?t=tFKbzBBpJzM1PycP8ZSIYw&s=09

- Linkedin: https://www.dhirubhai.net/in/ekedoro-elizabeth

- Medium: https://ekedoroelizabeth.medium.com


Good luck, and may your experience of modifying files and directories in Linux be both successful and rewarding!


要查看或添加评论,请登录

Elizabeth Ekedoro的更多文章

社区洞察

其他会员也浏览了