brian
brian

Reputation: 85

Recursively filter & sort files by timestamp

I wanted to recursively search a directory for a particular file extension, and wanted the files to appear by timestamp (i.e. newest ones first).

Ideally, I'd want something like:

ls -R -lth *.txt

but this doesn't work, although parts of it work:

ls -lth *.txt
ls -R -lth

How do I need to modify my 'ls' command?

thanks!

Upvotes: 0

Views: 619

Answers (2)

svinther
svinther

Reputation: 111

I prefer this, because it also works with a large number of files

find . -name '*.txt' -printf '%T@ %t %p\n' | sort -k 1 -n

Upvotes: 0

Freddy
Freddy

Reputation: 4708

If you're using bash, you could enable the globstar shell option and use **/ to match zero or more subdirectories:

shopt -s globstar # enable globstar
ls -lth **/*.txt
shopt -u globstar # disable globstar

Upvotes: 1

Related Questions