|
|
how to del files older than a calculated date
Hi,
I run a counterstrike server that generates log files of what's going
on with the server. The logs are starting to take up too much space
on my hard drive. Log files greater than 30 days old are not needed.
I'd like to write a daily cron job that automatically deletes logs
greater than 30 days old.
2 questions: how can I calculate the date to be 30 days in the past
and what command can I issue to delete files based on the file system
time stamp?
I'm using BASH on Redhat linux version 9 with a 2.4 kernel. Any help
is appreciated as always. Thank you,
Rob
|
|
0
|
|
|
|
Reply
|
rbaxter
|
10/7/2003 3:33:28 PM |
|
Rob Baxter <rbaxter@cyence.com> wrote:
> 2 questions: how can I calculate the date to be 30 days in the past
> and what command can I issue to delete files based on the file system
> time stamp?
Assuming that you replace "startdir" with the path to the directory
containing your logfiles, the following should delete any ordinary files
in startdir (and any files in subdirectories of startdir) that have not
been modified the last 30 days:
find startdir -type f -mtime +30 -exec rm -f {} \;
I'd recommend that before you run this the first time, you do this:
find startdir -type f -mtime +30 -exec ls -l {} \;
and verify that it is picking up *only* the files you really want
to delete.
--
Wayne Brown | "When your tail's in a crack, you improvise
fwbrown@bellsouth.net | if you're good enough. Otherwise you give
| your pelt to the trapper."
"e^(i*pi) = -1" -- Euler | -- John Myers Myers, "Silverlock"
|
|
0
|
|
|
|
Reply
|
Wayne
|
10/7/2003 4:08:14 PM
|
|
> find startdir -type f -mtime +30 -exec rm -f {} \;
>
> I'd recommend that before you run this the first time, you do this:
>
> find startdir -type f -mtime +30 -exec ls -l {} \;
>
> and verify that it is picking up *only* the files you really want
> to delete.
That worked perfectly. Thanks very much. Now I will research what
find and exec are, and how they work :)
|
|
0
|
|
|
|
Reply
|
rbaxter
|
10/8/2003 1:42:08 AM
|
|
Rob Baxter <rbaxter@cyence.com> wrote:
> That worked perfectly. Thanks very much. Now I will research what
> find and exec are, and how they work :)
You're welcome. Try "man find" for further info. ("exec" is one of
the built-in options for "find.")
--
Wayne Brown | "When your tail's in a crack, you improvise
fwbrown@bellsouth.net | if you're good enough. Otherwise you give
| your pelt to the trapper."
"e^(i*pi) = -1" -- Euler | -- John Myers Myers, "Silverlock"
|
|
0
|
|
|
|
Reply
|
Wayne
|
10/8/2003 5:42:49 PM
|
|
Rob Baxter wrote:
> Hi,
>
> I run a counterstrike server that generates log files of what's going
> on with the server. The logs are starting to take up too much space
> on my hard drive. Log files greater than 30 days old are not needed.
> I'd like to write a daily cron job that automatically deletes logs
> greater than 30 days old.
>
> 2 questions: how can I calculate the date to be 30 days in the past
> and what command can I issue to delete files based on the file system
> time stamp?
>
> I'm using BASH on Redhat linux version 9 with a 2.4 kernel. Any help
> is appreciated as always. Thank you,
Somewhat tangentially,
man logrotate
|
|
0
|
|
|
|
Reply
|
Ian
|
10/8/2003 9:10:09 PM
|
|
|
4 Replies
537 Views
(page loaded in 0.059 seconds)
Similiar Articles: delelte dirs older than 2 hours by find with solaris 9 - comp.unix ...... I can only select files older than ... way to delete old files? find & exec VS find & xargs ..... system ... and date y - comp.unix.solaris ... delelte dirs older than 2 ... Calculated Find - comp.databases.filemaker... partially on what you use as your > smallest component (in date/time ... Calculated Find - comp.databases.filemaker Find age ... how to del files older than a calculated ... find files between date x and date y - comp.unix.solaris ...I know how to find file newer than X > or older than Y, but I ... calculate day, hour , sec between dates - comp.lang.java ... find files between date x and date y - comp ... Script to check files in adirectory older than X hours - comp.unix ...Script to check files in adirectory older than X hours - comp.unix ... find files between date ... calculate day, hour , sec between dates - comp.lang.java ..... simple ... How to delete files two days older from system - comp.unix.admin ...Is there any unix command or date option there so I can use in script? example ... Than x Days on Linux - How-To Geek We currently are using this to delete files older than 60 ... How to get a 180days back date - comp.unix.solaris... calculate the date back to 180days >and remove the files ... del Rio <delrio@mie.utoronto.ca> wrote: >Zubair wrote: > >> Stuck in the middle: as I have to calculate the date ... calculate day, hour , sec between dates - comp.lang.java ...... online years between date Days between dates Calculator . ... Views (0.055 seconds) Tweet ... in adirectory older than X hours - comp.unix ... find files between date x ... Solaris 10: How can I get a date that is exactly 30 days back ...... in C you could > calculate ... How can I get a date that is exactly 30 days back ... How to delete files two days older ... Script to check files in adirectory older than X ... ntpd, boot time, and hot plugging - comp.protocols.time.ntp ...... remove it and let the server re-calculate, than ... A fix that works even with older untamed versions is to craft a frequency file with ... came up with a wildly wrong date ... Pay by date... - comp.databases.filemaker> Pay by Date = Creation Date + Other File::Number of Days Thought I was right... ... possible the system doesn't maintain historical data on-line (older than some date ... how to del files older than a calculated date - Linux / Unix ...Hi, I run a counterstrike server that generates log files of what's going on with the server. The logs are starting to take up too much space on my hard drive. Delete Files Older Than Date Using Batch Files | Scott ElkinThis problem has nagged at me for years. Here is a batch command to delete files on a Windows 2003 machine. Forfiles -pC:\backup -s -m*.* -d-5 -c "cmd /c del /q @path" 7/25/2012 5:06:43 PM
|
|
|
|
|
|
|
|
|