Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a ton of files that are timestamped directories. These all look like

2011-06-24_13.53.36  // a directory name for june 24th, 1:53:36 pm

I have thousands of these directories. I want to do operations on some of the older ones. Let's say I give it a string for date time that matches that exact format, like i'll give it

2011-06-25_00.00.00 // june 25th, 12am

I want to find all the directories BEFORE my time. So if i give the string for 12am on june 25th, i want to find all the directories before then.

Can this be done using find?

If not i can find EVERY directory i have like this and then filter after wards. The created/modified dates are not tied to the actual timestamp im looking for (that would make this easier)

share|improve this question

migrated from Jul 12 '11 at 2:35

This question came from our site for professional and enthusiast programmers.

I don't think you can just use find for this, at least not directly. If it's just thousands of folders and not hundreds of thousands or millions, the it'd probably be easiest just to go through each folder and check it's name field by field. In a script* – inTide Jul 11 '11 at 19:12

This format is string sortable, so you could just do a string compare on the strings of the same format.

I don't know if/how find can do this, but here is a possible Perl example (if all folders are in the same location and have the same format):

perl -E "-d && $_ lt '2011-06-25_00.00.00' && say while <*>"



(Which is correct for my little test.)

share|improve this answer

One quirky way :

  • Assuming you only have these directories under working directory
  • You are in bash or similar

Following command should give you list of files "alphabetically older" than Jun 25.

ls -l | head -`ls -l | grep -n 2011-06-24 | cut -d: -f1`

Now note that the name pattern criteria is 2011_06_24 (to avoid 2011_06_25 in the result)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.