This article is a mirror article of machine translation, please click here to jump to the original article.

View: 18907|Reply: 0

[linux] Delete the found files in batches under Linux

[Copy link]
Posted on 11/19/2021 11:28:11 AM | | | |
Requirements: I want to delete log log files in batches under the Linux system, because there are too many modules, there are many logs, and under different directories, we can output the path of these logs through the find command, how to delete them in batches?

The first way

To batch delete files of the same format in a multi-level directory in Linux, you can use the find + exec command combination:

For example, in the deleted old directory, in all subdirectories, the file method with the suffix .l is:

find old -type f -name "*.l" -exec rm -f {} \;

Illustrate:

•old: The starting directory to be found, search for the subdirectory under it

•-type f : The file type is a normal file If the target file is a directory, use -type d

•-name "*.l" : means that the file name matches "*.l", and double quotation marks cannot be missing!

•rm -f {} : When deleting, {} indicates the found file without prompting

ps : between {} and \Spaces are required

The second way

Use the xargs parameter

find . -name "._*" | xargs rm -rf







Previous:Spring Cloud Nacos multi-NIC registration binds a specified IP address
Next:Visual Studio 2022 Enterprise Edition download and installation tutorial
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com