The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



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.

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 07:25 AM
only find files older than x minutes old dsimpg1 Shell Programming and Scripting 1 05-18-2006 11:48 PM
Find files older than 20 days & not use find halo98 Shell Programming and Scripting 2 05-18-2006 02:19 PM
Find files older than 5 days and remove tem after listing ypatel6871 UNIX for Dummies Questions & Answers 1 09-05-2005 11:00 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-27-2007
caprikar caprikar is offline
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
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,710
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
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,910
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
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,710
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 On




All times are GMT -4. The time now is 01:28 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