so I have looked at every single script on here regarding deleting directories older than 14 days. The Script I wrote works with files but for some reason it is not deleting the directories. So here is my scripts.
所以我在这里查看了有关删除超过14天的目录的每个脚本。我写的脚本使用文件,但由于某种原因它不删除目录。所以这是我的脚本。
#!/bin/bash
find /TBD/* -mtim +1 | xargs rm -rf
So this code successfully deleted the FILES inside TBD but it left two directories. I checked the timestamp on them and they are atleast 2 days since last modification according to the timestamp. Specifically Dec 16 16:10 So I can't figure this out. My crontab I have running this runs every minute and logs and in the log it only shows.
所以这段代码成功删除了TBD中的FILES,但它留下了两个目录。我检查了它们的时间戳,根据时间戳,它们是自上次修改后至少2天。特别是12月16日16:10所以我无法弄清楚这一点。我的crontab我运行它每分钟运行并记录日志,它只显示日志。
+ /scripts/deletebackups.sh: :2:BASH_XTRACEFD=3xargs rm -rf
+ /scripts/deletebackups.sh: :2: BASH_XTRACEFD=3find /TBD/contents TBD/contents -mtime +1
I used contents since the contents are actually peoples name in our pxe server. I checked every file and folder INSIDE these two directories and their timestamps are the same as the parent directory as they should be but it's still not deleting.
我使用内容,因为内容实际上是我们的pxe服务器中的人名。我检查了这两个目录中的每个文件和文件夹,它们的时间戳和它们应该是的父目录相同,但它仍然没有删除。
Could it be a permissions thing? I wrote the script using sudo nano deletebackups.sh When I type ls under TBD in the far left it shows drwxr-xr-x 3 hscadministrator root 4096 DEC 16 16:10 for each of the two directories that won't delete. I'm not overly familiar with what all those letters mean.
这可能是权限吗?我使用sudo nano deletebackups.sh编写脚本当我在最左边的TBD下键入ls时,它显示drwxr-xr-x 3 hscadministrator root 4096 DEC 16 16:10对于两个不会删除的目录。我对这些字母的含义并不过分熟悉。
Other iterations of this code I have already attempted are
我已经尝试过的这段代码的其他迭代
find /TBD/* -mtime +1 rm -r {} \;
2 个解决方案
#1
11
To delete directories in /TBD older than 1 day:
要删除超过1天的/ TBD中的目录:
find /TBD -mtime +1 -type d | xargs rm -f -r
#2
4
Add -exec and -f to your find:
在您的查找中添加-exec和-f:
find /TBD/* -mtime +1 -exec rm -rf {} \;
Note, if you're looking to delete files older than 14 days, you need to change mtime:
请注意,如果您要删除超过14天的文件,则需要更改mtime:
-mtime +14
#1
11
To delete directories in /TBD older than 1 day:
要删除超过1天的/ TBD中的目录:
find /TBD -mtime +1 -type d | xargs rm -f -r
#2
4
Add -exec and -f to your find:
在您的查找中添加-exec和-f:
find /TBD/* -mtime +1 -exec rm -rf {} \;
Note, if you're looking to delete files older than 14 days, you need to change mtime:
请注意,如果您要删除超过14天的文件,则需要更改mtime:
-mtime +14