Delete directories older than X days

so I reviewed every script here regarding deleting directories older than 14 days. script I wrote work with files, but for some reason it does not delete directories. So here are my scripts.

#!/bin/bash find /TBD/* -mtim +1 | xargs rm -rf 

Thus, this code successfully deleted FILES inside TBD, but it left two directories. I checked the timestamp on them and they are at least 2 days after the last modification according to the timestamp. In particular, December 16, 16:10 So I can not understand this. My crontab, which I run, starts every minute, and it only shows the logs and logs.

 + /scripts/deletebackups.sh: :2:BASH_XTRACEFD=3xargs rm -rf + /scripts/deletebackups.sh: :2: BASH_XTRACEFD=3find /TBD/contents TBD/contents -mtime +1 

I used the content, because in fact this name is actually on our pxe server. I checked every file and INSIDE folder in these two directories, and their timestamps match the parent directory as they should be, but they still are not deleted.

Could this be a fix? I wrote a 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 will not be deleted. I am not very familiar with what all these letters mean.

Other iterations of this code that I have already done are

 find /TBD/* -mtime +1 rm -r {} \; 
+6
source share
2 answers

Deleting directories in / TBD older than 1 day:

 find /TBD -mtime +1 -type d | xargs rm -f -r 
+11
source

Add -exec and -f to your find:

 find /TBD/* -mtime +1 -exec rm -rf {} \; 

Note. If you want to delete files older than 14 days, you need to change mtime:

 -mtime +14 
+4
source

Source: https://habr.com/ru/post/979879/


All Articles