What is the difference between the Linux command rmdir and rm?

  
                

The rmdir and rm commands are deleted commands on Linux systems. The difference is that the rmdir command is used to delete directories. The rm command can delete files and directories at the same time. Here is a detailed introduction to the Linux commands rmdir and rm. .

rm command can delete files or directories simultaneously

rmdir Commands

1. Name: rmdir

2. Applicable objects: a current All users of directory operation permissions

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

4. Role: delete empty directory

5. Parameters Detailed explanation:

-p If the parent directory becomes an empty directory after the subdirectory is deleted, it will be deleted along with the parent directory.

-v Last time I said, I won't describe it here. See

6. Example:

1.[snms@snms test]$ ls

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

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

4.dir2 dir3< Br>

5.[snms@snms test]$ rmdir dir1 #Cannot delete non-empty directories

6.rmdir: failed to remove “dir1”: The directory is not empty

7 [snms@snms test]$ rmdir dir1/dir3

8.[snms@snms test]$ ls

9.dir1

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

11.[snms@snms test]$ ls

12.[snms@snms test]$

rm command introduction
>

1.Name: rm

2. Applicable objects: All users

3. Command format: rm [-firv] [dirName/dir]

4. Role: delete files or directories

5. Detailed parameters:

-f Even if the file attribute is read-only (ie write-protected), it is deleted directly

-i Ask for confirmation before deleting

-r Delete directory and all files under it

6.Example:

1.[snms@snms test] $ ll

2. Total 12

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

4.-r--r-- R-- 1 linuxidc linuxidc 5 04-04 08:49 cc

5.drwxrwxr-x 2 linuxidc linuxidc 4096 04-04 08:48 dir1

6.[snms@snms test] $ ll dir1

7. Total 4

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

9.[snms@snms test] $ rm -i aa

10.rm: Do you want to delete the normal file “aa”? y

11.[snms@snms test]$ rm cc

12.rm: Do you want to delete the write-protected normal file “cc”? n

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

14.[snms@snms test]$ ls

15.dir1

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

17.[snms@snms test]$ ls

18.[snms@snms test]$

In addition, when using rm --help, you will find the following very useful things in the description

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

2. directory and its contents below.

3. To delete the first character (“-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 usually restore the file to its original state.

7. The contents of this file cannot be restored. Please consider using shred.

The above is the introduction of the Linux command rmdir and rm difference, rm command and rmdir command can be used in some places, but the effect of using rm and rmdir command to delete is still different.

Copyright © Windows knowledge All Rights Reserved