Oldest files

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


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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


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.

     see http://people.freenet.de/slgig/op_en/operations.html#queues

     for more details.
bt707Author Commented:
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,
You are welcome!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.