How to delete directory and files more old than a week

Kernels & Hardware, configuring network, installing services

How to delete directory and files more old than a week

Postby GabrieleMax » 2017-04-19 18:52

Hi everybody!

I use my Stretch server also like a nas for my ipcameras and I'd like to delete everything more old than a week!

For example now I have:

Code: Select all
root@Server01:/home/ipcam# ls
20170407  20170409  20170411  20170413  20170415  20170417  20170419
20170408  20170410  20170412  20170414  20170416  20170418  test
root@Server01:/home/ipcam#

Today I should have just directory from 12 to 19 april, I tryed in crontab this "script" but it doesn't work:

Code: Select all
find /home/ipcam/* -mtime +7 -delete

Thanks in advance for your help! :)

GabrieleMax
GabrieleMax
 
Posts: 36
Joined: 2016-09-07 20:24
Location: Senigallia

Re: How to delete directory and files more old than a week

Postby Dai_trying » 2017-04-19 20:39

If you are running this script as root you will probably need to put the full path to find (ie /usr/bin/find) in the crontab entry.
Dai_trying
 
Posts: 287
Joined: 2016-01-07 12:25

Re: How to delete directory and files more old than a week

Postby GabrieleMax » 2017-04-20 18:10

Dai_trying wrote:If you are running this script as root you will probably need to put the full path to find (ie /usr/bin/find) in the crontab entry.


Ok, I did it, on a newsgroup someone wrote me this:

Code: Select all
find . -depth -mtime +7 -print0 | xargs -0 -- rm -rf

It could happen to have a directory more old than a week but with new and old files inside...
GabrieleMax
 
Posts: 36
Joined: 2016-09-07 20:24
Location: Senigallia

Re: How to delete directory and files more old than a week

Postby Dai_trying » 2017-04-20 18:29

As a side note, have you tried using ZoneMinder I used it to set-up a camera monitoring solution a while back and it has the option to only keep x amount of data (settable by time or size), it was very useful to me.
Dai_trying
 
Posts: 287
Joined: 2016-01-07 12:25

Re: How to delete directory and files more old than a week

Postby GabrieleMax » 2017-04-21 10:54

Dai_trying wrote:As a side note, have you tried using ZoneMinder I used it to set-up a camera monitoring solution a while back and it has the option to only keep x amount of data (settable by time or size), it was very useful to me.


Thanks for your other reply! :)

Yes, I tryed it 4-5 years ago but I don't remember why I stopped to use it... maybe I could/should try to use it today!

It could be useful if you have a smarttv with a webbrowser, so it could be possible to see everycams on every tv, when I'm outside I use Tinycam on android smartphone by vpn/ssl tunnel.

GabrieleMax
GabrieleMax
 
Posts: 36
Joined: 2016-09-07 20:24
Location: Senigallia


Return to System configuration

Who is online

Users browsing this forum: No registered users and 13 guests

fashionable