[英]Find specific parent folder and delete files inside sub-folders in Linux
What I want to happen is delete non-images in assets/uploads
folder but skip the uploads
folder if the parent folder is not assets
folder.我想要发生的是删除
assets/uploads
文件夹中的非图像,但如果父文件夹不是assets
文件夹,则跳过uploads
文件夹。
site1.dev/assets/uploads (delete non-images)
site2.dev/assets/uploads (delete non-images)
site3.dev/assets/uploads (delete non-images)
site4.dev/uploads (skip deletion)
site5.dev/assets/uploads (delete non-images)
This is the code that I used find assets/uploads -name "*.php" -type f -print0 | xargs -0 /bin/rm -f
这是我使用的代码
find assets/uploads -name "*.php" -type f -print0 | xargs -0 /bin/rm -f
find assets/uploads -name "*.php" -type f -print0 | xargs -0 /bin/rm -f
but it tedious to run this code each site. find assets/uploads -name "*.php" -type f -print0 | xargs -0 /bin/rm -f
但在每个站点运行此代码很乏味。
Thank you in advance.先感谢您。
To delete "none-images" as described, you need to first discover the image extensions that are being used and ignore them with find through the -not flag要按照描述删除“无图像”,您需要首先发现正在使用的图像扩展名并通过 -not 标志使用 find 忽略它们
find ./assets/uploads -type f -not /assets/uploads/*.img -not /assets/uploads/*.jpeg -delete
Answer to my own quesion find. -path '*/assets/uploads/*.php' -type f -delete
回答我自己的问题
find. -path '*/assets/uploads/*.php' -type f -delete
find. -path '*/assets/uploads/*.php' -type f -delete
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.