How to View, Delete, Copy, and make a new Directory in Debian 11

How to View, Delete, Copy, and make a new Directory in Debian 11?

Introduction

Make a new Directory in Debian 11 with just few clicks.

Debian is a popular and widely used Linux distribution known for its stability, security, and flexibility. It is an operating system that is extensively used in servers, PCs, and even embedded computers. It is free and open-source. As a user of Debian, it is essential to learn how to use it efficiently to take advantage of its features and capabilities. Debian 11 comes with a variety of tools and commands that can be used to manage files and directories on your system.

In this context, viewing the current directory means knowing which directory you are currently in. By default, when you open a terminal in Debian, it starts in your home directory, but you can navigate to other directories using various commands. However, it is essential to know the current directory you are working in, especially when running commands that require specifying the file path.

To view the current directory in Debian 11, you can use the pwd command.

  • Pwd Command

The pwd command, which stands for “print working directory,” is used to show the complete path to the current directory. You can use it by entering pwd in the Debian terminal and then pressing the Enter key to execute it.

The pwd command shows the complete path to the current directory. The result of the pwd command, for instance, will be as follows if you open a terminal in your user account’s home directory:

/home/username

Here, “username” refers to your actual username. The forward slash at the beginning of the path indicates the root directory (“/”), which is the top-level directory in the file system.

It’s important to keep in mind that the pwd command only displays the current directory’s full path, not its contents. The ls command is used to inspect the directory’s contents as well as to list the files and directories in the current directory.

Here’s an illustration of how to combine the pwd and ls commands:

Open the terminal in Debian.

Type the pwd command and press Enter. The output should be the full path of your current directory.

$ pwd /home/username

Type the ls command and press Enter. The output should be a list of the files and directories in your current directory.

$ ls Desktop Documents Downloads Music Pictures Public Templates Videos

Here, the output shows that the current directory contains several subdirectories, such as “Desktop”, “Documents”, “Downloads”, and so on. You can navigate to any of these directories using the cd command followed by the directory name.

In conclusion, the pwd command is a simple and essential command in Debian that allows you to view the full path of the current directory. By using this command, you can quickly know which directory you are working in and navigate the file system more efficiently.

  • Deleting a directory

To delete a directory in Debian 11, you can use the rmdir command. This command only works for empty directories. An error warning will appear if you attempt to use it on a directory that contains files or other directories. Use the rm command with the -r option to remove a non-empty directory.

Here’s how to delete an empty directory using the rmdir command:

rmdir directory_name

The directory name should be changed to the name of the directory you want to remove.

Here’s an illustration. Consider the situation where you want to remove the empty directory “my directory” that you have. Use the command given below:

rmdir my_directory

If the directory is not empty, you can remove it recursively by using the rm command with the -r option. Here is how to delete a non-empty directory using the rm command:

rm -r directory_name

Replace the directory name with the name of the directory you want to delete.

This is one instance. Let’s imagine you wish to remove a directory called my directory that has certain files and subdirectories. Use the command given below:

rm -r my_directory

This will remove my directory and all its contents.

  • Copying a directory

To copy a directory in Debian 11, you can use the cp command with the -r option. This option tells the cp to copy the directory and its contents recursively.

Here’s how you can use the cp command to copy a directory:

cp -r source_directory destination_directory

Substitute the names of the directories you wish to copy (the source directory and the destination directory) with their respective names.

Here’s an example. Let’s say you have a directory called my directory and you want to make a copy of it called my directory copy. Use the command given below:

cp -r my_directory my_directory_copy

This will create a new directory called my directory copy that contains the same files and subdirectories as my directory.

  • Creating a directory

In Debian 11, you can use the mkdir command to create a new directory. In this command, “make directory” is abbreviated.

Here is how to create a new directory using the mkdir command:

mkdir directory_name

Replace the directory name with the name you want to give to the new directory.

Here’s an example. Let’s say you want to create a new directory called my new directory. You can use the following command:

mkdir my_new_directory

The current directory will then contain a brand-new, empty directory called my new directory. The complete path to the directory can be specified if you wish to create it in a particular location:

mkdir /path/to/new_directory

The whole path to the directory you wants to create should be substituted for /path/to/new directory. This will create a new directory in the location you selected, which will be empty.

Conclusion

To manage files and directories in Debian 11, you can use several different commands. Files and directories can be viewed using the ls command, deleted using the rm command, copied using the cp command, and new directories can be created with the mkdir command. These basic commands are essential for managing files and directories in Debian 11.

Don’t forget to leave your valuable comments and do check the below articles.

https://linuxiron.com/how-to-install-debian-11-the-exact-way/

https://linuxiron.com/how-to-install-debian-11-on-a-vmware-workstation/

https://linuxiron.com/how-to-manage-a-process-in-debian-11/

Leave a Comment

Your email address will not be published. Required fields are marked *