Linux rmdir command

Source: Internet
Author: User

Linux rmdir command

Delete files and directories on the Linux Command Line. We have discussed the use of the rm command. However, there is another related command line tool dedicated to directory deletion. This tool is rmdir. In this tutorial, we will discuss it based on some simple examples.

Linux rmdir command

The rmdir (remove directory) command is used to delete a directory. However, the directory is usually empty. The syntax is as follows:

Rmdir [OPTION]... DIRECTORY...

The following is a description of man's document:

If the directory is empty, delete it.

The following Q & A cases may inspire you to understand how this program works.

Q1. how does the rmdir command work?

This is very direct. You only need to pass the directory name as the input parameter.

For example:

Rmdirtest-dir

How the rmdir command works

Q2. how can I make rmdir ignore non-empty directories?

Normally, the rmdir command will throw an error when you delete a non-empty directory. However, if necessary, you can use the -- ignore-fail-on-non-empty option to ignore it.

For example:

How to Make rmdir ignore non-empty directories

Q3. how do I have the rmdir command remove the parent directory?

Like mkdir, you can perform operations in the parent directory by asking the rmdir command. This means that you can delete the parent directories of directories and directories at one time. This function can be implemented using the-p command option.

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

Rmdir-p test/test-dir/

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

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

If you are still impressed, you can also delete the directory by providing the-r option's rm command. What is the difference between rmdir and rm-r? Rmdir only applies to empty directories. You cannot use rmdir to delete non-empty directories.

Therefore, rmdir is a valid tool when you need to check whether the directory is empty.

Summary

I believe you will agree that rmdir is not a complex command that is hard to understand and use. In addition, it only provides a small number of command line options. We have discussed almost all the options here. If you want to learn better, just practice the cases mentioned in this tutorial.

This article permanently updates link: https://www.bkjia.com/Linux/2018-02/151007.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.