Differences between Linux commands rmdir and rm

Source: Internet
Author: User

Differences between Linux commands rmdir and rm

Rmdir is a command that corresponds to mkdir. Mkdir is used to create a directory, while rmdir is the command to delete a directory.

The rm command can delete files or directories at the same time.

Rmdir command Introduction

1. Name: rmdir

2. target objects: all users with the permission to operate the current directory

3. Command Format: rmdir [-p-v] [dirName]

4. Role: delete an empty directory

5. Detailed description of parameters:

-P: when the sub-directory is deleted and the parent directory becomes empty, the sub-directory is deleted together with the parent directory.

-V: As mentioned last time, I will not describe it here. For details, see

6. Example:

1. [bkjia @ bkjia test] $ ls

2. [bkjia @ bkjia test] $ mkdir-p dir1/dir2 dir1/dir3

3. [bkjia @ bkjia test] $ ls dir1/

4. dir2 dir3

5. [bkjia @ bkjia test] $ rmdir dir1 # non-empty directories cannot be deleted.

6. rmdir: failed to remove "dir1": the directory is not empty.

7. [bkjia @ bkjia test] $ rmdir dir1/dir3

8. [bkjia @ bkjia test] $ ls

9. dir1

10. [bkjia @ bkjia test] $ rmdir-p dir1/dir2

11. [bkjia @ bkjia test] $ ls

12. [bkjia @ bkjia test] $

Rm command Introduction

1. Name: rm

2. Target audience: All Users

3. Command Format: rm [-f-I-r-v] [dirName/dir]

4. Role: delete files or directories

5. Detailed description of parameters:

-F even if the file attribute is read-only (write protection), it is deleted directly.

-I ask for confirmation one by one before deletion

-R: Delete the Directory and all its files.

6. Example:

1. [bkjia @ bkjia test] $ ll

2. A total of 12

3.-rwxrwxr-x 1 bkjia 5 04-04 08:48 aa

4.-r -- 1 bkjia 5 04-04 08:49 cc

5. drwxrwxr-x 2 bkjia 4096 04-04 dir1

6. [bkjia @ bkjia test] $ ll dir1

7. Total 4

8.-rwxrwxr-x 1 bkjia 5 04-04 08:47 bb

9. [bkjia @ bkjia test] $ rm-I aa

10. rm: Do you want to delete the common file "aa "? Y

11. [bkjia @ bkjia test] $ rm cc

12. rm: Do you want to delete the "cc" common file with write protection "? N

13. [bkjia @ bkjia test] $ rm-f cc

14. [bkjia @ bkjia test] $ ls

15. dir1

16. [bkjia @ bkjia test] $ rm-r dir1

17. [bkjia @ bkjia test] $ ls

18. [bkjia @ bkjia test] $

In addition, when you use rm -- help, you will find the following useful items in the description:

1. By default, rm does not delete the directory. You can use the -- recursive (-r or-R) option to delete each listed

2. Directory and its contents.

3. to delete a file with the first character "-" (for example, "-foo"), use one of the following methods:

4. rm ---foo

5. rm./-foo

6. Please note that if you use rm to delete a file, you can still restore it to its original state. If you want to ensure

7. The content of the file cannot be restored. Please use shred.

This article permanently updates the link address:

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.