Delete files except those whose name matches a string

删除回忆录丶 提交于 2021-01-28 07:24:44

问题


I'm trying to delete all files (include subdir) in a directory but only files which not match specific file name: "equipe" "match" "express"

I'm trying to do it with this command

find . -type f '!' -exec grep -q "equipe" {} \; -exec echo rm {} \;
  1. That doesn't work. It echos files with "equipe" inside
  2. How can I do it with multiple strings? ("equipe" "match" "express")

回答1:


You may use this find:

find . -type f -not \( -name '*equipe*' -o -name '*match*' -o -name '*express*' \) -delete


来源:https://stackoverflow.com/questions/51951725/delete-files-except-those-whose-name-matches-a-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!