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!

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.

ls -t | head -1  | read oldest
ls -rt | head -1 | read youngest
echo " oldest = $oldest, youngest = $youngest"
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;
}