Skip to content
Advertisement

How to find newest files with a certain name?

Suppose I have a directory with many files of the same name in subdirectories (for example, comes up when keeping BibTeX files for multiple academic papers).

What’s the best way to find the newest version of a file with a given name?

I’ve come up with the following command

find . -name "someFile" -exec ls -alF {} ;

which lists all the files named someFile along with their dates, but does not sort them from old to new.

Note that the -t option to ls can’t be used here because it is being run separately for each file.

Advertisement

Answer

Combining the proposed solutions results in the following, pretty clean one:

find . -name "someFile" -exec ls -latR {} +

which shows all versions of the file, newest first.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement