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 Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Finding the oldest file in a particular directory pavan_movva Shell Programming and Scripting 4 04-08-2009 07:24 AM
Finding the oldest file janet Shell Programming and Scripting 5 03-23-2009 10:31 AM
Find Oldest file in a directory tree rahulrathod Shell Programming and Scripting 25 01-12-2009 12:45 PM
how to grep the oldest file in a directory ericaworld Shell Programming and Scripting 1 05-29-2007 01:24 PM
Removing the oldest file in a directory pavan_movva Shell Programming and Scripting 2 10-10-2006 11:38 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 02-27-2002
bergerj3 bergerj3 is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 6
Oldest File In A Directory

I'm writing a script to find the oldest file in a directory. I know this can be done by using ls -rt | tail -1 but these are rather large directories and that can be somewhat slow since the script will be running constantly.

Are there any other ways to do this that would be faster? I looked to see if find would have any options but I didn't see anything. Any suggestions would be appreciated.

Joel
  #2 (permalink)  
Old 02-27-2002
usfrog usfrog is offline
Registered User
  
 

Join Date: Dec 2001
Location: San Jose CA
Posts: 32
awk can also make it.
in the portion of scripts below I look fore some core* archive files and delete the oldest:

ls -r core* | awk '{ fname=$1 } END{ system("rm " fname) }'
  #3 (permalink)  
Old 02-27-2002
witt
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
I think that find is better that ls command.

example to find archives with more that 10 days and delete them :

find /directore -mtime +10 -type f -exec rm {} \;

or

find / -mtime +10 -name "core" -type f -exec rm {} \;

or another option with ls command :

ls -r core* | xargs rm

Witt
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 12:40 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