Discuss Linux rmdir commands based on some simple examples

To remove files and directories on the Linux command line, we have already discussed the use of the rm command. However, there is another related command line tool specifically for directory deletion. This is the tool that is referred to as rmdir. In this tutorial, we will discuss it based on some simple examples.

Linux rmdir command

As the name suggests, the rmdir (remove directory) command is specifically for deleting directories, but usually the directory is empty. Here is its syntax:

Rmdir[OPTION]...DIRECTORY...

The following is a description of the man documentation:

If the directory is empty, delete it.

In understanding how this program works, the following Q&A style case may give you a better inspiration.

Q1. How does the rmdir command work?

This is very straightforward, just pass the directory name as an input parameter to it.

such as:

Rmdir test-dir

Discuss Linux rmdir commands based on some simple examples

Q2. How do I make rmdir ignore non-empty directories?

Normally, the rmdir command throws an error when you delete a non-empty directory. However, if you want, you can use the --ignore-fail-on-non-empty option and ignore it.

For example:

Q3. How do I get the parent directory from the rmdir command?

Like mkdir, you can perform operations on its parent directory by asking the rmdir command. This means that you can delete the superordinate directories of directories and directories at once. This feature can be implemented with the -p command option.

For example, the following command will delete the "test" and "test-dir" directories.

Rmdir -ptest/test-dir/

Note: For this to work, all deleted parent directories should not contain any directories other than the empty directory to be deleted.

Q4. What is the difference between rmdir and rm -r?

If you still have an impression, you can also delete the directory by providing the rm command with the -r option. What is the difference between rmdir and rm -r? Rmdir works only for empty directories - there is no way to delete non-empty directories using rmdir.

Therefore, rmdir is an effective tool for removing the need to check if the directory is empty.

to sum up

I believe you will agree that rmdir is not a complicated command that is difficult to understand and use. Other than that, it only provides a few command line options. Here, we have discussed almost all the options, if you want to master better, practice the cases mentioned in this tutorial. About rmdir, there are man documents here, so you can do it from time to time.

Screw Terminal Block

Screw Terminal Connector,Pcb Screw Terminal,Screw Terminal Block Connector,Screw Type Terminal Blocks

Cixi Xinke Electronic Technology Co., Ltd. , https://www.cxxinke.com