Sponsored Content
Special Forums UNIX and Linux Applications Finding the oldest file in a directory without ls Post 302361999 by jim mcnamara on Wednesday 14th of October 2009 04:54:47 PM
Old 10-14-2009
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"

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

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... (2 Replies)
Discussion started by: bergerj3
2 Replies

2. Shell Programming and Scripting

Removing the oldest file in a directory

Hi all, I need your assistance in removing the oldest file in a directory. I posted the same thread 3 days back and I got the following answer ls -1 -t | tail -1 | xargs rm which is not covering the case when there are directories older than the oldest file. So, could you please... (2 Replies)
Discussion started by: pavan_movva
2 Replies

3. Shell Programming and Scripting

how to grep the oldest file in a directory

Hi, Please help me out I want to grep the oldest file in a directory, could I use "ls" command? and how? thanx in advance (1 Reply)
Discussion started by: ericaworld
1 Replies

4. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

5. Shell Programming and Scripting

Setting Variable to oldest file in a directory

I am using a bash script to perform some automated maintenance on files in a directory. When I run the script using $sh -x script.sh <directory> the script works fine. It sets the variable to the oldest file, and continues on. However when I run the script like this $./script.sh <directory>, it... (5 Replies)
Discussion started by: spaceherpe61
5 Replies

6. Shell Programming and Scripting

Find Oldest file in a directory tree

This might just be one command. Any1 having the solution? Thanks, Rahul. (25 Replies)
Discussion started by: rahulrathod
25 Replies

7. Shell Programming and Scripting

Finding the oldest file

Hi:- I need help with a script I need to modify: - what's the best/easiest way to find out the oldest file in a directory and then move this file to another directory? Thanks, (5 Replies)
Discussion started by: janet
5 Replies

8. Shell Programming and Scripting

Finding the oldest file in a particular directory

Hi all, I am a newbie to scripting and I need your help regarding finding the oldest file in a particular directory. My intention is to remove that oldest file. Are there any options available with the "find" command to do this.. Thanks in advance for your help Pavan (4 Replies)
Discussion started by: pavan_movva
4 Replies

9. Shell Programming and Scripting

Deleting the oldest file in a directory

Hey! I have found similar posts both here and on other sites regarding this, but I cannot seem to get my script to work. I want to delete the oldest file in a test directory if there are more than two files. My script is currently: #!/bin/bash MEPATH=/usr/local/bin/test FILECOUNT=`ls... (4 Replies)
Discussion started by: Immolation
4 Replies

10. UNIX for Advanced & Expert Users

Finding oldest files

There are some 25,000 files in 7,000 directories in my source library and I am trying to find oldest files. I am running this find: find /usr/mysrc -name "*." -type f -mtime +8000 -exec ls -l {} 2>/dev/null and playing with the days parameter for mtime, but the output is not sorted... (3 Replies)
Discussion started by: migurus
3 Replies
SVN::Web::Browse(3pm)					User Contributed Perl Documentation				     SVN::Web::Browse(3pm)

NAME
SVN::Web::Browse - SVN::Web action to browse a Subversion repository SYNOPSIS
In config.yaml actions: ... browse: class: SVN::Web::Browse action_menu: show: - directory link_text: (browse directory) ... DESCRIPTION
Returns a file/directory listing for the given repository path. OPTIONS
rev The repository revision to show. Defaults to the repository's youngest revision. TEMPLATE VARIABLES
at_head A boolean value, indicating whether or not the user is currently browsing the HEAD of the repository. context Always "directory". entries A list of hash refs, one for each file and directory entry in the browsed path. The list is ordered with directories first, then files, sorted alphabetically. Each hash ref has the following keys. name The entry's name. path The entry's full path. rev The entry's most recent interesting revision. size The entry's size, in bytes. The empty string '' for directories. type The entry's "svn:mime-type" property. Not set for directories. author The userid that committed the most recent interesting revision for this entry. date The date of the entry's most recent interesting revision, formatted according to "Time and date formatting" in SVN::Web. msg The log message for the entry's most recent interesting revision. rev The repository revision that is being browsed. Will be the same as the "rev" parameter given to the action, unless that parameter was not set, in which case it will be the repository's youngest revision. youngest_rev The repository's youngest revision. EXCEPTIONS
(path %1 does not exist in revision %2) The given path is not present in the repository at the given revision. (path %1 is not a directory in revision %2) The given path exists in the repository at the given revision, but is not a directory. This action is only used to browse directories. COPYRIGHT
Copyright 2003-2004 by Chia-liang Kao "<clkao@clkao.org>". Copyright 2005-2007 by Nik Clayton "<nik@FreeBSD.org>". This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See <http://www.perl.com/perl/misc/Artistic.html> perl v5.14.2 2012-06-11 SVN::Web::Browse(3pm)
All times are GMT -4. The time now is 11:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy