In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article Xiaobian detailed introduction of "Linux how to delete the directory", the content is detailed, the steps are clear, the details are handled properly, I hope this "Linux how to delete the directory" article can help you solve your doubts, following the editor's ideas slowly in-depth, let's learn new knowledge.
When you delete a directory using the Desktop File Manager, the directory has actually been moved to the wastebasket and can be easily restored.
Be careful when deleting files or directories from the command line, because once you delete a directory using the commands described in this article, you cannot fully restore it.
On most Linux file systems, deleting a directory requires write access to the directory and its contents. Otherwise, you will receive a "do not allow operation" error.
The directory name that contains spaces must be escaped using a backslash (/).
Delete directory rmdir
Rmdir is a command line utility for deleting empty directories. You need to delete a directory only if the directory is empty, without checking whether the directory is empty.
To delete the directory rmdir, type the command, and then type the name of the directory you want to delete. For example, to delete the directory named linuxmi, type:
Linuxidc@linuxidc:~$ rmdir linuxmi if the directory is not empty, you will receive the following error:
Rmdir: failed to delete 'linuxmi': directory is not empty
In this case, you need to use the rm command or delete the directory contents manually before you can delete it.
Delete directory rm
Rm is a command line utility for deleting files and directories. Unlike the command rmdir, rm can delete empty and non-empty directories.
By default, rm does not delete directories when used without any option. 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 can type:
Rm-r linuxmi if a directory or file in a directory is write protected, you will be prompted to confirm deletion. To delete a directory without prompting, use the following-f option:
Rm-r dirname to delete more than one directory at a time, use the rm command followed by directory names separated by spaces. The following command deletes each listed directory and its contents:
The-I option rm-r linuxmi linuxmi linuxidc tells rm to prompt you to confirm the deletion of each subdirectory and file. This can be a bit annoying if the directory contains a large number of files, so you can consider using the option of-I that prompts you only once before continuing with the deletion.
Rm-rI linuxidc confirm that you want to delete the directory, enter y and click Enter.
Rm: remove 1 argument recursively? Y
You can also use regular extensions to match and delete multiple directories. For example, to delete all first-level directories or files in the current directory that end with all _ bak, you would use the following command:
It may be risky to use regular extensions when rm-r * _ bak deletes directories. It is recommended that you first use this ls command to list directories so that you can view the directories that will be deleted before running the rm command.
Delete directory find
Find is a command-line utility that allows you to search for files and directories based on a given expression and perform actions on each matching file or directory.
The most common case is to use the find command to delete directories according to the pattern. For example, to delete all directories in the current working directory that end in _ cache, run:
Find. -type d-name'* _ cache'-exec rm-r {} +
Let's analyze the above command:.-Recursively search the current working directory (.). -type d-restricts searches to directories. -name'* _ cache'-search only directories that end with _ cache-exec-execute an external command with optional parameters, in this case rm-r. {} +-appends the found file to the end of the rm command.
Delete all empty directories
To delete all empty directories in the directory tree, you will use:
Find / dir- type d-empty-delete the following is an explanation of the options used: / dir- recursively searches the / dir directory. -type d-restricts searches to directories. -empty-restricts the search to empty directories only. -delete-deletes all empty directories found in the subtree. -delete can only delete empty directories.
Use the-delete option with caution. The find command line is evaluated as an expression, and if you first add the-delete option, the command removes everything below the specified starting point. Always use-delete as the last option, and test the command without using the-delete option before deleting it.
/ bin/rm: this error message appears when Argument list too long uses this rm command to delete a directory that contains a large number of files. This occurs because the number of files is greater than the system limit for the size of the command line arguments.
There are several different solutions to this problem. For example, you can cd manually or use a loop to delete subdirectories to directories one by one.
The simplest solution is to first use the find command to delete all files in the directory, and then delete the directory:
Find / dir-type f-delete & & rm-r / dir read here, this article "how to delete a directory in Linux" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it to understand it. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.