I have forgotten the name of a file which is in a directory or one of its subdirectories. I remember the file's extension (.nb) and know approximately when it was created. How can I list all file with this extension in the current directory and subdirectories along with their creation dates? I'm using Mac OS X.

4 Answers 4


The easy way to do this is with zsh, which is installed by default on macOS. Its glob qualifiers let you select and sort files by timestamp and other metadata. Zsh doesn't support creation times, but it supports modification times and inode change times; one of them probably matches the creation time.

This lists the 100 ([1,100]) most recent (om) regular (.) files with the .nb extension in the current directory and its subdirectories (**/):

zsh -c 'ls -ltr **/*.nb(.om[1,100])'

This lists files modified between 7 and 14 days ago:

zsh -c 'ls -ltr **/*.nb(.m+6m-14)'

This should accomplish what you want.

find . -type f -name '*.nb'|xargs stat -f '%c %N'|sort


find . -type f -name '*.nb' find all files with .nb extension.

xargs stat -f '%c %N' print out the files with the unix timestamp in the front.

sort sort it.

  • Creation date would be birth time in the mac world. You might consider replacing change time-%c with birth time-%B.
    – fd0
    Commented Nov 3, 2016 at 12:26

For bash (not mac):

find . -type f -iname '*.nb'| xargs -d '\n' stat -c '%z %N'|sort

find all entries of type 'file' in the current directory and below, matching pattern

(-iname to ignore case)

pipe it to xargs

(-d '\n' change delimiter to linefeed to allow for spaces in file names)

then to stat

(-c for output format %z = last status change %N quoted file name)

and sort the output

find -name '*.nb' -exec ls -rtl {} +

Will show detailed info on all files matching the pattern, and sort them from oldest to newest (you can have from newest to oldest by removing the r option from the ls command).

The + at the end means you execute the command at the end of the search instead of running it for each match.

NOTE: this will only work with a reasonable amount of matches, if the command line is too long for ls it will be split up in several ls's, resulting in several sorted subsets while the whole list will not be sorted correctly (thank you @Gilles and @rudimeier for pointing it out).

  • 1
    This will not work if there are too many files from one single ls command.
    – rudimeier
    Commented Nov 2, 2016 at 14:59
  • @rudimeier Why is that ? Commented Nov 2, 2016 at 15:47
  • 1
    @ValentinB. Because if the command line is too long, find will execute ls several times, with successive subsets of the files to fit within the limit. Each subset will be sorted but not the whole. Commented Nov 2, 2016 at 22:06
  • Thank you for the explanation @Gilles. I will edit my answer accordingly. Commented Nov 3, 2016 at 8:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .