The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
grep unix.com with google



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-27-2007
Registered User
 

Join Date: Dec 2003
Posts: 7
how to find files older than 4hours in HP-UX

Hi,
I want to find the files older than 4 hours and remove them in HP-UX 11.23. Can anyone tell me how to do this?
Thanks,
GK
  #2 (permalink)  
Old 11-27-2007
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,006
One way using perl:

Code:
#!/bin/ksh
filetime()
{
    perl  -e '
         $mtime = (stat $ARGV[0])[9];
          print $mtime;
         '  $1
}
now=$(date +%s)
now=$(( $now - 14400 ))
find /path/to/file -type f | \
while read filename 
do
     ftime=$(filetime $filename)
     if [[ $ftime -ge $now ]] ; then
        continue
     fi
     rm -f $file
done

  #3 (permalink)  
Old 11-27-2007
fpmurphy's Avatar
Moderator
 

Join Date: Dec 2003
Location: Florida
Posts: 2,030
It is a pity HP-UX's find does not support the -older option. It has the -newer option.

Then you could simply do something like:


Code:
touch -t YYYYMMDDhhmmss /tmp/touchfile
find ./ -older /tmp/touchfile -exec rm -f {}\;

  #4 (permalink)  
Old 11-27-2007
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,006
You can do ! -newer

Code:
touch -t [4hours ago] touchfile
find /path/to/files ! -newer touchfile  -exec rm -f {} \;

Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to find files older than 2 hours pt14 AIX 3 03-05-2008 12:31 PM
find files older than a given file Shivdatta Shell Programming and Scripting 5 07-24-2006 08:25 AM
only find files older than x minutes old dsimpg1 Shell Programming and Scripting 1 05-19-2006 12:48 AM
Find files older than 20 days & not use find halo98 Shell Programming and Scripting 2 05-18-2006 03:19 PM
Find files older than 5 days and remove tem after listing ypatel6871 UNIX for Dummies Questions & Answers 1 09-05-2005 12:00 PM



All times are GMT -4. The time now is 09:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0