Oldest files

Posted on 2004-11-28
Last Modified: 2013-12-27
I have a directory that has sub directories and I need to find the oldest 10 files in each of the sub diretories, I have a command that does the search but it comes back with the 10 newest files
and I need the 10 oldest, what do I need to change.

command that I need to modify

# for dirs in `find /mail/queues/ -type d -depth` ; do echo $dirs; ls -Altr $dirs | tail -10; done


Question by:bt707
    LVL 38

    Accepted Solution

    You need to get rid of the "r" in your command, make it :

    # for dirs in `find /mail/queues/ -type d -depth` ; do echo $dirs; ls -Alt $dirs | tail -10; done

    man ls
    to learn more details.

    LVL 38

    Expert Comment

    Oops, my mistake.

    yuzh is right.

    # for dirs in `find /mail/queues/ -type d -depth` ; do echo $dirs; ls -Altr $dirs | tail -10; done
    # for dirs in `find /mail/queues/ -type d -depth` ; do echo $dirs; ls -Alt $dirs | tail -10; done

    As my experience, /mail/queue stores all the emails in queue and it doesn't have subdirectory. (Please correct me
    if I were wrong)
    So I will simply the script to
    # ls -lt /mail/queues/ | grep '^-' | tail -10


    LVL 38

    Expert Comment

    Hi Wesly,

         The standard sendmail configuration use /var/spool/mqueue,  bt707 might use
    multiple mail queues for the sendmail config, so it is possible to have subdirectories.


         for more details.

    Author Comment

    Thanks yuzh, I took the 'r' out as you said and that fixed it.

    Yes we do have multiple directories, we use Sun One Iplanet and it uses on directory for each channel with about 12 to 20 sub directories, they get created automatically as needed.

    Thanks agian,
    LVL 38

    Expert Comment

    You are welcome!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
    FreeBSD on EC2 FreeBSD ( is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now