Home  >  Article  >  Operation and Maintenance  >  How to delete a directory in linux

How to delete a directory in linux

尚
Original
2019-12-25 11:24:5715115browse

How to delete a directory in linux

How to delete a directory in Linux:

Use the rmdir command to delete a directory

rmdir is a command used to delete empty directories Command line utility. You only need to delete the directory if it is empty, there is no need to check if the directory is empty.

To delete the directory rmdir , type the command followed by the name of the directory you want to delete. For example, to delete a directory named linuxmi, type:

linuxidc@linuxidc:~$ rmdir linuxmi

If the directory is not empty, you will receive the following error:

rmdir: Deletion of 'linuxmi' failed: Directory is not empty

How to delete a directory in linux

In this case, you need to use the rm command or manually delete the directory contents before you can delete it.

Delete Directories Using the rm Command

rm is a command line utility for deleting files and directories. Unlike the command rmdir, rm can delete both empty and non-empty directories.

By default, rm does not delete directories when used without any options. To delete empty directories, use the -d(--dir) option. If you want to delete a non-empty directory and all its contents, use the -r (--recursive or -R) option.

For example, to delete a directory named linuxmi and all its contents, you would type:

rm -r linuxmi

If a directory or file in the directory is write-protected, you will be prompted to confirm the deletion. To delete directories without prompting, use the following -f option:

rm -r dirname

To delete multiple directories at once, use the rm command, followed by the directory names separated by spaces. The following command will delete each listed directory and its contents:

rm -r linuxmi linuxmi linuxidc

The -i option tells rm to prompt you for confirmation of deletion of each subdirectory and file. This can be a bit annoying if the directory contains a lot of files, so you might consider using the -I option which only prompts you once before proceeding with the deletion.

rm -rI linuxidc

Please enter y if you want to delete the directory and click Enter.

rm: remove 1 argument recursively? y

How to delete a directory in linux

Online learning video sharing: linux video tutorial

The above is the detailed content of How to delete a directory in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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