简体   繁体   English

如何“在多个目录(文本文件)中查找所有xml文件并删除”

[英]How to "find all xml files in multiple directories (textfile) and delete"

I have a text file containing the full path to about 1000 directories.我有一个包含大约 1000 个目录的完整路径的文本文件。 Each on a separate line.每个在单独的行上。 I would like to delete all .xml files contained in these folders.我想删除这些文件夹中包含的所有 .xml 文件。 I can obtain this one at a time using:我可以使用以下方法一次获得这个:

find /mnt/local/hhd1/output/data/2010-aug-ph1/ -name "*.xml" -type f -delete

but obviously will take a long time to do by hand.但显然手工制作需要很长时间。 How do I get find to read each line and perform the delete from a text file?我如何找到读取每一行并从文本文件中执行删除?

Use a loop to read the directory names from your file and issue a find ... -delete on each of them:使用循环从您的文件中读取目录名称,并对每个目录发出find ... -delete

#!/bin/bash

while read -r dir; do
  find "$dir" -name "*.xml" -type f -delete
done < file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM