Want to sort files by update date including sub-directories

With ls, -R will recurse directories and -t will sort by modification. However, it traverses directories recursively and applies -t to each directory. It doesn't accumulate all files from all directories and then sort. (As far as I understand, the latter is what you want)

With gnu find(1) you can specify the format of output to include the number of seconds since epoch and the filename, then you can pipe this to sort(1).

find . -type f -printf "%T@ %f\n" | sort -n > out.txt

I am not sure what exactly do you mean by update dates, but you are using -r option which according to man does this -

-r Reverse the order of the sort to get reverse lexicographical order or the oldest entries first (or largest files last, if combined with sort by size

I think this should be good enough for you if you need files sorted by time.

ls -lRt

If you don't need all the other stuff listed by ls then you can use -

ls -1Rt

To capture the result in a file, you can use the redirection operator > and give a file name. So you can do something like this -

ls -lRt > sortedfile.list

Update:

find . -type f -exec ls -lt {} +

This will sort files so that the newest files are listed first. To reverse the sort order, showing newest files at the end, use the following command:

find . -type f -exec ls -lrt {} +

Tags:

Ls