简体   繁体   English

在 Linux 中查找特定父文件夹并删除子文件夹中的文件

[英]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.

相关问题 在Linux上使用wget扫描子文件夹中的特定文件 - Using wget on Linux to scan sub-folders for specific files 如何找到各个子文件夹中的所有tar文件,然后将它们解压缩到找到的同一文件夹中? - How to find all tar files in various sub-folders, then extract them in the same folder they were found? 合并子文件夹,Linux - Merging Sub-Folders together, Linux 在文件夹和子文件夹中运行 all.bach - run all .bach in a folder and sub-folders 如何显示子文件夹中的文件数量? - How to show the amount of files in the sub-folders? 如何访问 LINUX 中 LAMPP 下不同子文件夹中的多个 php 文件 - how to access multiple php files in different sub-folders under LAMPP in LINUX 在Linux下,如何在C的文件路径中找到子文件夹的权限? - How can I find the permissions for sub-folders in file's path in C under Linux? 命令列出Linux目录中的所有文件夹和子文件夹 - command to list all the folders and sub-folders in a directory in linux 删除linux目录中的所有文件夹和文件,除了一个文件夹和该文件夹中的所有内容 - delete all folders and files within a linux directory except one folder and all contents inside that folder 如何从linux中的特定文件夹中删除文件? - How to delete files from specific folders in linux?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM