3 Ways to Delete Directory in Linux via Terminal (Complete+Image)
As we know, Linux is an operating system (OS)) the best that has a lot of fans. The types of Linux are familiar such as Debian, Ubuntu, Red Hat, Fedora, and others. For those of you Linux users, of course, you are familiar with the use of terminal-his. This Linux terminal is the same as command prompt or cmd on Windows. Well, some of the functions commonly used through the Linux terminal, such as activities to install programs, run programs, create, move, copy, edit, and delete folders and files, and much more.
There are two types of Linux operating systems, the first server and the second desktop. Unlike the desktop type which provides a GUI interface, the server type relies on shell or command line, in other words you give commands through the terminal. For those of you who are new to the server type, you may be confused when operating it.
How to Delete Directories on Linux
In this discussion, I will use the terminal to delete a directory on Linux by applying the commands command line Linux. Here are some command line which you can use on the terminal to delete directories in Linux and how to apply them.
1. Deleting Empty Directories
Order rmdir used to delete empty directories on Linux. This command cannot be used for folders that contain or have folders/files in them. The methods include the following.
1. Open your terminal. Point the terminal command to the directory to be deleted. Go to the parent directory of the directory you want to delete using the command:
CD folder_name
For example, as in the image below, I want to delete folder1 which is in the directory My Documents/folders. The folder is empty, so I can use the command rmdir to delete it. Go to the directory with the command:
CD My Documents/folders
2. After that type the following command.
rmdir folder_name
To remove folder1 I use the command:
rmdir folder1
3. Your directory has been successfully deleted. You can prove this bylist fill in your parent directory with command ls -al. In the sample image, it can be seen that folder1 no longer in the directory my folder.
2. Delete Empty / Contented Directories
The rm -r command can be used to delete a directory that is empty or has content, i.e. there are folders and/or files in it. Before successfully deleting a directory, this command will ask for confirmation of deletion when run against a directory that does not have access rights write (write-potected).
As we know, directory permissions are divided into 3, namely reads, writes, and execute or usually written with rwx. Where read means the user can only see files/folders, write means that the user can write files/folders (including editing and deleting), and execute to execute a file/folder (useful for entering into a folder).
The following is an example of implementing the command rm -r.
1. First, you open a terminal and use the command CD to go to the directory you want to delete.
CD folder_name
As for the image below, I will delete folder2. There is a file named file1.txt and folders Duty in the directory folder2. You should note that the folder Duty only have access rights read(r), seen by the absence of the letter w in the line (dr–r–r–).
2. Type the command:
rm -r folder_name
The implementation in the image you can see is indicated by the second arrow.
3. Next, the deletion you ordered will be processed. A confirmation will appear as shown in the image where you can type y to be absolutely sure of deleting the directory.
4. Your directory has been successfully deleted. You can prove this bylist fill in your parent directory with command ls -al. In the sample image, it can be seen that folder2 no longer in the directory my folder.
3. Delete Directories/Files Without Permission
This command is similar to the previous one, namely rm -r. It’s just that the difference lies when the command is executed. Order rm -rf it no longer asks for your permission to actually delete the directory you want, but instead deletes it immediately when run.
Here’s the implementation of the command rm -rf.
1. Open your terminal and use the command CD to go to the directory you want to delete.
CD folder_name
As for the image below, I will delete folder3. There is a folder exercise and a file named test.txt in the directory folder3. You should note that the file test.txt only have access rights read(r), seen by the absence of the letter w in the line (r–r–r–). This is more or less the same as the rm -r case above, where in the directory you want to delete there is a file/folder with the status write-protected.
2. Apply the delete command with the following syntax:
rm -rf folder_name
Command implementation rm -rf you can see in the image, which is pointed to by the second arrow.
3. Your directory has been successfully deleted. Order rm -rf looks not asking for confirmation again to delete the directory folder3. You can prove this bylist fill in your parent directory with command ls -al. In the sample image, it can be seen that folder3 no longer in the directory my folder.
Closing
The three commands above you can use to delete an empty folder. As for the containing folder, you can choose between commands rm -r and rm -rf, depending on your taste. Order rm -r you can also use it to check if in your directory there are files/folders that areprotect.
That’s how to delete a directory on Linux. If there is something you want to respond to, please fill in the comments field below. Thank you.
Post a Comment for "3 Ways to Delete Directory in Linux via Terminal (Complete+Image)"