Linux system delete folder command

1. Use the rm command to delete folders (commonly used commands)

When using  rm the command to delete a folder , be sure to add  -r the or  -R option, otherwise an error will be reported. This option means to delete the folder recursively , you can delete all the files under the folder. Plus  -f option will force delete without giving any prompt.

# 删除目录不加 -r 会报错
$ rm folder
rm: cannot remove ‘folder’: Is a directory

# 正确删除目录
$ rm -r folder

# 强制删除目录
$ rm -rf folder

2. Use the rmdir command to delete the folder

        The rmdir command is remove directory an abbreviation of English words, and its main function is to delete folders. But please note that this command can only be used to delete empty folders , and if the folder is not empty, an error will be reported.

$ rmdir folder
rmdir: failed to remove ‘folder’: Directory not empty

 So if you need to use  rmdir the command to delete a folder, you need to clear the folder first and then delete it .

# 先清空文件夹
$ cd folder
$ rm -rf *

# 再使用 rmdir 命令删除该文件夹
$ cd ..
$ rmdir folder

 The rmdir command to delete a folder   is too troublesome and redundant, so there are very few scenarios where the rmdir command is used

-------------------------------------------------- -------No text below---------------------------------------- --------------

Note: For study only, record questions and reference, encourage each other!

Refer to the reprinted article:
1. Linux system delete folder command

Guess you like

Origin blog.csdn.net/qq_39715000/article/details/125022315