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