|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Scripting Question
I need to write a shell script that I can add to as time passes, that looks at a certain directory, and removes files older than X days. The directory contains many different report files, all named as "REPORTNAME.XXXXX" where X is a random string for the report.
I need to have different days retention for each report. I'm sure this is a quick one-liner and I can just add lines and adjust the days for each different report I want included in the script, but so far the different variations of find, etc. I have used have not really given me what I want. For now I am using a -exec ls -l to show the output, but anticipate changing that to -exec rm {} \; when all is said and done. If someone could help with the output using the above method, or if you have a better suggestion, I would truly appreciate it. |
|
#2
|
||||
|
||||
|
You might find it easier to write the script in perl. I have an example in my stash of a script which uses the perl stat file test to test the age of a file before removing it. I bet you could hack it to do what you want in just a couple of minutes.
christo
__________________
. Spiration channels: Free scripts, programming tutorials and articles Dotcut alerts: Online Press cuttings / news alerts Clearprop: UK microlight school, wiltshire Uk dating: UK safe dating with Topdates About Christo . . |
|
#3
|
|||
|
|||
|
Isn't this just:
find . -name REPORT.\* -mtime +5 -print | xargs ls -l |
|
#4
|
||||
|
||||
|
Quote:
that's a nice use of 'find' that I've never thought of before ![]() christo |
|
#5
|
|||
|
|||
|
find . -name REPORT.\* -mtime +5 -print | xargs ls -l
that is correct, this FASTER (find uses: ls -li) find . -name REPORT.\* -mtime +5 -ls NOTA: in this example using SVR4 find, the -print option is obsolete. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Scripting Question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|