Cron job to remove certain folders after a certain # of days?

a directory
/var/www/user/data/www/mysite.com/scrin/ it created a bunch of folders every day like this:
04-12-2017
05-12-2017
06-12-2017
.....
.....
in uploaded screenshots.
and not only
So how poveshat cron job to it from the directory /var/www/user/data/www/mysite.com/scrin/ deleted only folders of this type 04-12-2017 older than 8 days without affecting other folders?
June 10th 19 at 15:16
3 answers
June 10th 19 at 15:18
Solution
Thank you all in General, so that's who should:
@daily find /var/www/user/data/www/mysite.com/scrin -type d -name "*-*" -mtime +8 -exec rm-rf {} \; >/dev/null 2>&1
June 10th 19 at 15:20
Solution
this is so I know - douglas_Wehner commented on June 10th 19 at 15:23
1. Using find to find folders older than 8 days
2.To date this folder to convert the date in desired format matching the format of the folder name
3. Compare and if match remove.
Goes wrong? Or date, and folder names may not match? - Dejah.Reilly23 commented on June 10th 19 at 15:26
Yes.
but if I'm going to put
@daily find /var/www/user/data/www/mysite.com/scrin/ -mtime +8 -exec rm {} \;

then removed all folders from the scrin directories older than 8 days and I need Toko to delete folders older than 8 days like this: 04-12-2017 05-12-2017 and so on and others are not touched (because in this directory has many other folders which should never be removed under any circumstances). I.e. which have a say
-
they should Toko delete if older than 8 days. - douglas_Wehner commented on June 10th 19 at 15:29
find you can add a template directory name, using regex:
find /var/www/user/data/www/mysite.com/scrin/ -mtime +8-type d-regextype sed -regex ".*/[0-9]\{2\}\-[0-9]\{2\}\-[0-9]\{4\}" -exec rm {} \; - nikita.Stracke commented on June 10th 19 at 15:32
,
@daily find /var/www/user/data/www/mysite.com/scrin/ -mtime +8-type d-regextype sed -regex ".*/[0-9]\{2\}\-[0-9]\{2\}\-[0-9]\{4\}" -exec rm {} \;
will be scrin folder to remove folders from all types
04-12-2017
14-12-2017
01-01-2018
etc.
? - douglas_Wehner commented on June 10th 19 at 15:35
Yes , unable to check to run only instead of rm {} \; enter ls-l {} \;
displays a list of folders for deletion. - nikita.Stracke commented on June 10th 19 at 15:38
June 10th 19 at 15:22
Solution
will see if it will fit:
find ./* -mtime +8
Yes.
but if I'm going to put
@daily find /var/www/user/data/www/mysite.com/scrin/ -mtime +8 -exec rm {} \;

then removed all folders from the scrin directories older than 8 days and I need Toko to delete folders older than 8 days like this: 04-12-2017 05-12-2017 and so on and others are not touched (because in this directory has many other folders which should never be removed under any circumstances). I.e. which have a say
-
they should Toko delete if older than 8 days. - douglas_Wehner commented on June 10th 19 at 15:25
add a mask?
find /var/www/user/data/www/mysite.com/scrin/ -name "*2017" -mtime +8 -exec rm {} \;
- Dejah.Reilly23 commented on June 10th 19 at 15:28
and every year to redo it?
and it is possible something like this?
find /var/www/user/data/www/mysite.com/scrin/ -name "*2*" -mtime +8 -exec rm {} \;
? - douglas_Wehner commented on June 10th 19 at 15:31
Safer:
find /var/www/user/data/www/mysite.com/scrin/ -name "*20??" -mtime +8 -exec rm {} \;

And in your mask, any file that is somewhere two. - nikita.Stracke commented on June 10th 19 at 15:34
,
find /var/www/user/data/www/mysite.com/scrin -name "*2*" -mtime +8 -exec ls-l {} \;
he gave me all the screenshots of all the folders obsolete. And how to make it not climb in a folder not watched them but just looking at the date of the folder? - douglas_Wehner commented on June 10th 19 at 15:37
ls-ld {} - nikita.Stracke commented on June 10th 19 at 15:40

Find more questions by tags Cron