简体   繁体   English

删除除模式列表文件之外的所有文件

[英]delete all files except a pattern list file

I need to delete all the files in the current directory except a list of patterns that are described in a whitelist file ( delete_whitelist.txt ) like this:我需要删除当前目录中的所有文件,除了白名单文件( delete_whitelist.txt )中描述的模式列表,如下所示:

(.*)dir1(/)?
(.*)dir2(/)?
(.*)dir2/ser1(/)?(.*)
(.*)dir2/ser2(/)?(.*)
(.*)dir2/ser3(/)?(.*)
(.*)dir2/ser4(/)?(.*)
(.*)dir2/ser5(/)?(.*)

How can I perform this in one bash line?如何在一个 bash 行中执行此操作?

Any bash script can fit on one line:任何 bash 脚本都可以放在一行中:

find . -type f -print0 | grep -EzZvf delete_whitelist.txt | xargs -0 printf '%s\n'

Check the output and then, if it's OK:检查输出,然后,如果没问题:

find . -type f -print0 | grep -EzZvf delete_whitelist.txt | xargs -0 rm

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

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