Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with scripting

Status
Not open for further replies.

elzschiko

IS-IT--Management
Mar 8, 2005
2
DE
hello,

i need help with scripting @hp-ux 10.20 .

following problem:

a log-file directory has over 7000 files. i want to write a script the will delete the files. the problem is, not all files should be deleted. whats the syntax to delete the files until a specified date e.g. 31.12.2004

can anybody help me?

greets
daniel

: sorry for my bad english ;-)
 
man find

eg:

cd <log directory>

find <log directory> -mtime +<days since 31.12.2004> -exec rm {} \;

For safety, use

find <log directory> -mtime +<days since 31.12.2004> -exec ls -la {} \;

first to confirm that you're about to delete only the files you want to delete.
 
thx for your help.

to modify the command to show all files the will be older than 100 days, but not older than 200 days i would use the following command.
is it ok?

find <log directory> -mtime +<\>100\<200> -exec ls -la {} \;


greets
daniel
 
Sorry, no I don't think -mtime can be used like that. As far as I'm aware it can only be used in this context for files older than 100 (ie +100) days, which would include files older than 200 days by default. As I don't have an HP machine to hand, I stand to be corrected, however....
 
what about this:
find dir -mtime +100 -mtime -200 -exec ...
 
As far as I can see from a test using a Solaris box, this still returns details of files > 200 days old.
 
Ken,
I am quite surprised by your findings.
I tested with HP-UX, and it works.
As far as my understanding of find command goes, it should work for all flavours of UNIX.
'-mtime +100 -mtime -200' just means 'older then 100 days AND younger than 200 days'.
I haven't a Solarix box at hand though.
regards
 
maybe you have to give this 'AND' explicitely on some kinds of Unix:
find dir -mtime +100 -a -mtime -200 -exec ...
 
Interesting, Hoinz. Executing the command on one of our servers somes back with the following (extract):

drwxrwxrwx 11 ohmstest ohms 512 Sep 20 11:19 ..
-r--r----- 1 ohmstest ohms 8248 Feb 26 2004 act_trig.pc
-r--r----- 1 ohmstest ohms 6092 Sep 11 1996 addpymt.pc
-rwxrwxrwx 1 ohmstest ohms 13322 Aug 21 2003 addpymth.c
-rwxrwxrwx 1 ohmstest ohms 34684 Aug 21 2003 addpymth.o
-r--r----- 1 ohmstest ohms 5201 Feb 26 2004 addpymth.pc
-r--r----- 1 ohmstest ohms 26515 Sep 10 2003 agrupr.pc
-rwxrwxrwx 1 ohmstest ohms 68448 Aug 21 2003 cash.o
-r--r----- 1 ohmstest ohms 14847 Mar 1 2004 cash.pc
-r--r----- 1 ohmstest ohms 12419 Feb 11 2002 est_trig.pc
-r--r----- 1 ohmstest ohms 2235 Sep 2 2004 hpm_hun_hierarchy_movement
.sql
-r--r----- 1 ohmstest ohms 578 May 13 2002 is_alpha_hpm.c
-rwxrwxrwx 1 ohmstest ohms 70926 Aug 21 2003 lsc_bacs.c
-rwxrwxrwx 1 ohmstest ohms 90444 Aug 21 2003 lsc_bacs.o
-r--r----- 1 ohmstest ohms 22282 Feb 26 2004 lsc_bacs.pc
-rwxrwxrwx 1 ohmstest ohms 126394 Aug 21 2003 lsc_dirdebit.c
-rwxrwxrwx 1 ohmstest ohms 120368 Aug 21 2003 lsc_dirdebit.o
-r--r----- 1 ohmstest ohms 31377 Feb 18 2003 lsc_dirdebit.pc
-rwxrwxrwx 1 ohmstest ohms 112781 Aug 21 2003 lsc_set_est.c

From which you will see (if my interpretation is correct), that files from 2002/2003 and before are being returned. Whilst these are older than 100 days, they are not younger than 200. A Solaris limitation perhaps? I'd be interested to see the -mtime option for find from the HP man page (HP man site seems exceptionally slow today!).
 
yes, I see.
Here is an extract from my man pages.
Seems it doesn't help much.
In the descriptions of the primaries, the argument n represents a
decimal integer; +n means more than n, -n means less than n, and n
means exactly n.
.....
-mtime n True if the file modification time subtracted
from the initialization time is n-1 to n
multiples of 24 h. The initialization time
shall be a time between the invocation of the
find utility and the first access by that
invocation of the find utility to any file
specified in its path operands.
 
Thanks. I guess for other flavours one could touch a file with a date equivalent to 200 days previous and then use -mtime and -newer to filter out the files between 100 and 200 days old. Must give it a try when I get the chance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top