Technology and General Blog

The rm and rmdir instructions in Linux are employed to take away information and directories. Equally are potent commands and have pretty several command-line choices. The distinction concerning these commands is that rmdir only gets rid of “empty directories,” and it does not take out documents. If you use rmdir to remove a directory that consists of information, it will fail with the concept “Directory not empty”. If you need to take away a non-vacant directory, use the rm command.

Yet another stage is that when you clear away a file or listing making use of rm and rmdir, it is promptly eradicated as an alternative of moving to Trash. Therefore, you will require to be mindful while applying these commands as you will not get better the taken out documents and directories except you have a backup.

This post will describe how to use the rmdir command to take out directories in Linux and some illustrations.

Syntax of Rmdir Command

The syntax of rmdir command is as follows:

$ rmdir [OPTION]… Directory…

Get rid of a Listing applying rmdir

To take away a single empty listing, style rmdir followed by the listing title or path to the directory as follows:

$ rmdir ~/Files/myfiles

This command will clear away the “myfiles” directory positioned in the “~/Documents” path only if it is vacant. If the directory is not empty, the command will are unsuccessful and shows the “Directory not empty” concept.

Get rid of Many Directories utilizing rmdir

To get rid of multiple vacant directories, variety rmdir followed by the listing names or route to directories as follows:

$ rmdir ~/Paperwork/myfiles visuals games

This command will take away the “~/Files/myfiles”, “images”, and “games” directories only if they are vacant.

Verbose output

To see what the rmdir command is executing in the qualifications, use the -v option as follows:

$ rmdir -v ~/Documents/myfiles

For all the subsequent instructions, we will use the -v possibility.

Suppress Are unsuccessful on Non-Vacant Concept

As discussed earlier mentioned, the rmdir does not clear away the vacant directories. As a substitute, it fails and displays a “Directory not empty” concept. The –ignore-fail-on-non-vacant selection lets you to suppress the concept. Nonetheless, take note that it nonetheless does not eliminate the non-empty listing.

Let us say we want to clear away three directories named “games”, “videos”, and “images” wherever “games” and “images” directories are vacant when the “videos” directory is non-vacant.

$ sudo rmdir -v online games/ videos/ photos/

You can see in the output, rmdir command has eliminated the game titles and photos but failed to get rid of the video clips directory and shown the “Directory not empty” concept.

If we use the –ignore-fail-on-non-vacant alternative with the rmdir command, it will suppress the message nevertheless, it will not get rid of the non-empty listing.

$ sudo rmdir -v –dismiss-are unsuccessful-on-non-empty games videos images

Take out Listing and its dad or mum directories

The rmdir command also enables getting rid of the directories along with their father or mother directories. Let us say we have the next directory framework:

To get rid of the “docs” listing alongside with its guardian directories “myfiles” and “files”, use the -p command as follows:

$ sudo rmdir –v -p information/myfiles/docs/

The Linux rmdir command is a component of the GNU Main Utilities. It will allow you to eliminate empty directories in Linux. In this publish, we protected how to use the rmdir command along with some illustrations. To look at a lot more details, see the rmdir person webpage.

Leave a Reply

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