[unix] How do I list all the files in a directory and subdirectories in reverse chronological order?

I want to do something like ls -t but also have the files in subdirectories included. But the problem is that I don't want the output formated like ls -R does, which is like this:

[test]$ ls -Rt
b       testdir test

./testdir:
a

I want it to be formatted like the find command displays files in subdirectories. I.e:

[test]$ find .
.
./b
./test
./testdir
./testdir/a

But what find doesn't seem to do is order the result chronologically by last update time.

So how can I list all the files in a directory and subdirectories, in the format that find does, but in reverse chronological order?

This question is related to unix find ls

The answer is


Try find . -type d or find . -type d -ls


try this:

ls -ltraR |egrep -v '\.$|\.\.|\.:|\.\/|total' |sed '/^$/d'

The command in wfg5475's answer is working properly, just need to add one thing to show only files in a directory & sub directory:

ls -ltraR |egrep -v '\.$|\.\.|\.:|\.\/|total|^d' |sed '/^$/d'

Added one thing: ^d to ignore the all directories from the listing outputs


ls -lR is to display all files, directories and sub directories of the current directory ls -lR | more is used to show all the files in a flow.


If the number of files you want to view fits within the maximum argument limit you can use globbing to get what you want, with recursion if you have globstar support.

For exactly 2 layers deep use: ls -d * */*

With globstar, for recursion use: ls -d **/*

The -d argument to ls tells it not to recurse directories passed as arguments (since you are using the shell globbing to do the recursion). This prevents ls using its recursion formatting.


find -type f -print0 | xargs -0 ls -t

Drawback: Works only to a certain amount of files. If you have extremly large amounts of files you need something more complicated


Examples related to unix

Docker CE on RHEL - Requires: container-selinux >= 2.9 What does `set -x` do? How to find files modified in last x minutes (find -mmin does not work as expected) sudo: npm: command not found How to sort a file in-place How to read a .properties file which contains keys that have a period character using Shell script gpg decryption fails with no secret key error Loop through a comma-separated shell variable Best way to find os name and version in Unix/Linux platform Resource u'tokenizers/punkt/english.pickle' not found

Examples related to find

Find a file by name in Visual Studio Code Explaining the 'find -mtime' command find files by extension, *.html under a folder in nodejs MongoDB Show all contents from all collections How can I find a file/directory that could be anywhere on linux command line? Get all files modified in last 30 days in a directory FileNotFoundError: [Errno 2] No such file or directory Linux find and grep command together find . -type f -exec chmod 644 {} ; Find all stored procedures that reference a specific column in some table

Examples related to ls

'ls' is not recognized as an internal or external command, operable program or batch file 'ls' in CMD on Windows is not recognized Count number of files within a directory in Linux? How do I assign ls to an array in Linux Bash? How can I list (ls) the 5 last modified files in a directory? Regular Expression usage with ls How to get file creation date/time in Bash/Debian? List of All Folders and Sub-folders Listing only directories using ls in Bash? How to create ls in windows command prompt?