Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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 directory with files listed like so:


As you can see, the filename contains a datetime stamp. I want to return all files with the value 201303140000 or higher in the filename.

I can get use grep to grab the datetime portion of the filename, but I don't know how to pipe through a filter that can do something like X > 201303140000.

share|improve this question
up vote 3 down vote accepted

If your awk is the GNU awk, you can simply use:

find . -type f | awk '{ match($0, /2013[0-9]+/,arr)}  arr[0] >= 201303140000 '
share|improve this answer
I see what you're doing here. You're pulling all dates within filenames, grabbing the ones within my criteria, then for each remaining date you run a grep. This seems highly inefficient as I need to process thousands of files/filenames often. – Chaos Mar 24 '13 at 8:49
@Chaos I have updated final solution – Rahul Patil Mar 24 '13 at 10:34
Does GNU awk support 64-bit integers everywhere, even if the local C compiler is an old one without long long? – Gilles Mar 24 '13 at 15:41
@Gilles, awk uses doubles not integers. In this case though, you can force string comparison (arr[0] >= "201303140000") to avoid that kind of problem. – Stéphane Chazelas Mar 24 '13 at 16:35
Thanks Rahul, I changed the regex a little, but your solution works great! – Chaos Mar 26 '13 at 6:20

Perl to the rescue! Perl's -n switch works a bit like sed -n and perl is more powerful in its matching and arithmetic.

dennis@lightning:/tmp/foo$ ls -1
dennis@lightning:/tmp/foo$ ls | perl -ne '$d=$_; $d =~ s/.*?(\d+).*/\1/s; print if $d >= 201303140000'
share|improve this answer
Why down vote this answer? – warl0ck Mar 24 '13 at 11:36
You can simplify that to perl -ne 'print if /\d+/ && $& >= 201303140000' – Stéphane Chazelas Mar 24 '13 at 12:11
I tried this, and it works of course. Thanks for the suggestion – Chaos Mar 26 '13 at 6:22

With zsh:

setopt extendedglob # best in ~/.zshrc

print -rl abc<201303140000->.txt

<x-y> is a zsh globbing operator only available with extendedglob as it potentially conflicts with redirection operators.

share|improve this answer
Does zsh use 64-bit integers everywhere, even 32-bit systems whose C compiler is C89 and doesn't support long long? – Gilles Mar 24 '13 at 15:41
This is really convenient, thanks for the suggestion. – Chaos Mar 26 '13 at 6:21

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.