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 > Special Forums > UNIX and Linux Applications
.
google unix.com



UNIX and Linux Applications Discuss UNIX and Linux software applications. This includes SQL, Databases, Middleware, MOM, SOA, EDA, CEP, BI, BPM and similar topics.

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
Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names nikosey Shell Programming and Scripting 6 07-30-2008 09:46 PM
Removing the oldest file in a directory pavan_movva Shell Programming and Scripting 2 10-10-2006 11:38 AM
Oldest File In A Directory bergerj3 UNIX for Dummies Questions & Answers 2 02-27-2002 03:31 PM

Reply
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 10-14-2009
hiyofjord hiyofjord is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 1
Finding the oldest file in a directory without ls

I am trying to determine the oldest and most recent files in a huge directory. I am using an ls -tr statement outside my find statement. The directory is too big and I am getting an "arg list too long" error. Is there something I can put in my find statement that doesn't create a list to determine the earliest and most recent files so I do not have to use ls -tr and head -1 or tail -1. Below is one of the statements that I am trying to use.

firstFilePath=`ls -tr \`find "$fileDir" -name "$fileMask"\*"$fileType" -exec /bin/ls '{}' \;\` | head -1`


Thanks!
  #2 (permalink)  
Old 10-14-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
This is a good reason to consider a "filing system method" for large numbers of files - create a lot of strategic sub-directories - otherwise directory commands take forever.

There is no cure for the time these commands take except to to get your directory under control.

This is one way that does not require tail, which is slower than head.
Code:
ls -t | head -1  | read oldest
ls -rt | head -1 | read youngest
echo " oldest = $oldest, youngest = $youngest"
  #3 (permalink)  
Old 10-16-2009
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Code:
sub oldestFile {
  my $oldValue = 9999999999;
  my $oldestFile;
  my $file;
  my $statHandle;

  opendir(DIR, $DIR) || die "Unable to open Dir : $DIR <$!> \n";
  @files_arr = readdir(DIR);
  closedir(DIR);

  foreach(@files_arr) {
    next if ( /^\./ || -d $DIR.$_ );
    $file = $DIR . $_;
    $statHandle = stat($file);
    if ( $statHandle->mtime < $oldValue ) {
      $oldValue = $statHandle->mtime;
      $oldestFile = $file;
    }
  }
  return $oldestFile;
}
Reply

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 11:10 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