简体   繁体   English

从父目录中删除目录而不删除父目录 (Linux)

[英]Remove dirs from parent dir without deleting parent directory (Linux)

I am using the following command to remove all dirs older than 1 minute from the following path:我正在使用以下命令从以下路径中删除所有早于 1 分钟的目录:

find /myhome/me/xyz/[0-9][0-9]/[0-9][0-9][0-9][0-9]/my_stats/ -mmin +1 -exec rm -rf {} \;

folder structure: /home/myhome/me/xyz/<2 digit name>/<4 digit name>/my_stats/文件夹结构: /home/myhome/me/xyz/<2 digit name>/<4 digit name>/my_stats/

There could be multiple dirs or a single dir inside my_stats. my_stats 中可能有多个目录或单个目录。 The issue is when there is a single folder inside my_stats, the find command is deleting the my_stats dir as well.问题是当 my_stats 中只有一个文件夹时,find 命令也会删除 my_stats 目录。

Is there a way to solve this?有办法解决这个问题吗? Thanks谢谢

If I understand your question correctly you are probably looking for this:如果我正确理解你的问题,你可能正在寻找这个:

find /myhome/me/xyz/[0-9][0-9]/[0-9][0-9][0-9][0-9]/my_stats/ -mmin +1 -maxdepth 1 -mindepth 1 -type d -exec rm -rf {} \;

The -mindepth 1 parameter is what excludes the my_stats directory from the listing, as it is located at depth 0. -mindepth 1参数将 my_stats 目录从列表中排除,因为它位于深度 0。

The -maxdepth 1 parameter will not show subdirs of subdirs (you are deleting their parents recursively anyway). -maxdepth 1参数将不会显示子目录的子目录(无论如何您正在递归地删除它们的父目录)。

The -type d parameter limits the output to directories only, not ordinary files. -type d参数将 output 限制为仅目录,而不是普通文件。

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

相关问题 zip 父目录中的文件和文件夹,不包括父目录 + Amazon Linux - zip the files and folders inside a parent directory without including the parent directory + Amazon Linux 如何在父目录linux的子目录中查找和复制文件 - how to find and copy files in a sub directory from parent directory linux Linux CLI 找到没有子目录的目录路径 - 结果只有父路径 - Linux CLI find dir paths without their children - only parent paths as a result 预期父目录中的Linux脚本 - Linux script at parent directory expected Linux / php需要父目录 - Linux/php require parent directory 如何遍历linux中的目录并cd到特定目录 - How to traverse dirs in linux and cd into a specific dir Linux如何从父目录执行bash脚本? - Linux how do I execute a bash script from the parent directory? Linux:按名称顺序将多个文件批量重命名为父目录+后缀 - Linux: Batch rename multiple files to parent dir + suffix in order of name Linux:查找所有具有特定名称的文件夹,将其删除,然后将一个文件夹复制到这些文件夹的父目录中 - Linux: Find all folders with a particular name, remove them and have a folder copied into the parent directory of those folders linux文件和文件夹未继承父目录权限 - linux files and folders are not inheriting parent directory permissions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM