LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   "Remove file if older than ..." Help with a script (https://www.linuxquestions.org/questions/linux-general-1/remove-file-if-older-than-help-with-a-script-825347/)

rbalaa 08-10-2010 10:05 AM

"Remove file if older than ..." Help with a script
 
Hello all,

I need an expert to help me with a script to check in "FolderA" if there are files older than "x number of days", if found to remove them.

Thanks in advance for any help.

acid_kewpie 08-10-2010 10:13 AM

Code:

find /some/folder -mtime +28 -exec rm -f {}\;
that'll delete anything older than 28 days under that directory

Valery Reznic 08-10-2010 11:26 PM

Quote:

Originally Posted by acid_kewpie (Post 4061974)
Code:

find /some/folder -mtime +28 -exec rm -f {}\;
that'll delete anything older than 28 days under that directory

My version of find 4.4.2 (fedora 12) required space between {} and \;, i.e

Code:

find /some/folder -mtime +28 -exec rm -f {} \;

acid_kewpie 08-11-2010 12:37 AM

Quote:

Originally Posted by Valery Reznic (Post 4062560)
My version of find 4.4.2 (fedora 12) required space between {} and \;, i.e

Code:

find /some/folder -mtime +28 -exec rm -f {} \;

yep, so does every version I've ever used... my bad.

rbalaa 08-11-2010 08:04 AM

Thanks for the replies. I havn't hada chance to test it, but I will soon.

freeman118 09-13-2010 04:39 AM

Remove files out of 14 days
 
Hello All;

I used a code "find /some/folder -mtime +14 -exec rm -f {}\;" This code can been remove files out of 14 days. howerver, the output of file is different day.
You can see the file "20100830.txt" on 30, Aug
on other file "www20100830.tar.gz" on 31, Aug.

Please, see the further files as below:

I can not remove these two files on the same day.

Please, anyone can provide advise and deeply appreciated.

Thanks

[root@cron01]# ls -la
drwxr-xr-x 3 root root 3072 Sep 13 10:23 .
drwxr-xr-x 3 root root 80 Jun 22 11:31 ..
drwxr-xr-x 2 root root 2048 Sep 13 10:23 httpd
-rw-r--r-- 1 root root 10540589305 Aug 30 04:36 20100830.txt
-rw-r--r-- 1 root root 10674572196 Aug 31 04:37 20100831.txt
-rw-r--r-- 1 root root 10802965259 Sep 1 04:37 20100901.txt
-rw-r--r-- 1 root root 10924710265 Sep 2 04:38 20100902.txt
-rw-r--r-- 1 root root 11055977612 Sep 3 04:37 20100903.txt
-rw-r--r-- 1 root root 11184724742 Sep 4 04:38 20100904.txt
-rw-r--r-- 1 root root 11295158114 Sep 5 04:39 20100905.txt
-rw-r--r-- 1 root root 1860313830 Aug 31 04:41 www20100830.tar.gz
-rw-r--r-- 1 root root 1893674818 Sep 1 04:42 www20100831.tar.gz
-rw-r--r-- 1 root root 1888460332 Sep 2 04:42 www20100901.tar.gz
-rw-r--r-- 1 root root 1865787227 Sep 3 04:42 www20100902.tar.gz
-rw-r--r-- 1 root root 1995716158 Sep 4 04:43 www20100903.tar.gz
-rw-r--r-- 1 root root 1654560845 Sep 5 04:43 www20100904.tar.gz
-rw-r--r-- 1 root root 1853689856 Sep 6 04:37 www20100905.tar.gz

ghostdog74 09-13-2010 04:43 AM

don't actually understand what you want, but i am sure you can do something about the "www" files before you find and remove. maybe store them to some other directories?

acid_kewpie 09-13-2010 06:15 AM

I think you want the daystart option?
Code:

      -daystart
              Measure  times  (for  -amin,  -atime,  -cmin, -ctime, -mmin, and
              -mtime) from the beginning of today rather than  from  24  hours
              ago.  This  option only affects tests which appear later on the
              command line.

??

freeman118 09-13-2010 09:40 PM

Hi Acid and ghostdog74;

Thank you for your reply and kindly assistance.

Actullay I want to keep 14 days log files and remove log files out of 14 days.

The "*.txt" files and "*.gz" files are not create at the same day.

I have different to keep same files at same day.
(eg. Sep 5 04:39 20100905.txt
,,,Sep 6 04:37 www20100905.tar.gz )

Thank you


All times are GMT -5. The time now is 03:48 AM.