Home > Operation and Maintenance > Linux Operation and Maintenance > What is the command to delete a folder in Linux?

What is the command to delete a folder in Linux?

青灯夜游
Release: 2021-03-18 14:34:59
Original
107585 people have browsed it

Linux deletion folder commands include: 1. rmdir command, used to delete empty folders, the syntax format is "rmdir [-p] folder name"; 2. rm command, used to delete a file or Folder, the syntax format is "rm -rf folder name".

What is the command to delete a folder in Linux?

#The operating environment of this tutorial: Red Hat Enterprise Linux 6.1 system, Dell G3 computer.

① Linux delete folder command: rmdir

rmdir command usage scenario:

When there is an empty directory to be deleted, you can use the rmdir command. If the given directory is not an empty directory, an error message will appear.

Command syntax:

rmdir [-p] [目录名]
Copy after login
  • -p After deleting the specified directory, if the upper directory of the directory has become an empty directory, delete it together.

Example of rmdir command to delete a folder:

There is only dir1 directory under directory team03. When deleting dir1, team03 will also be deleted

#rmdir –p team03/dir1
Copy after login

② Linux delete folder command: rm

rm command usage scenario:

Many people are accustomed to using rmdir to delete folders, but rmdir is only suitable for deleting empty folders. Once the folder is not If it is empty, you will fall into deep distress. At this time, you can use the rm -rf command.

Command syntax:

rm -rf 目录名字
Copy after login
  • -r is recursive downward, no matter how many levels of directories there are, delete them all

  • -f means to delete directly without any prompt.

rm command to delete a folder example:

rm -rf /var/log/httpd/access
Copy after login

will delete the /var/log/httpd/access directory And all files and folders under it

Note when using the rm command:

Be very careful when using this rm -rf. Linux does not have a recycle bin. Many friends did not see this important prompt information before using it, so it is difficult to retrieve it after deleting it. In addition, rm is also a commonly used Linux file deletion command.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What is the command to delete a folder in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template