如何按照相反的时间顺序列出一个目录和子目录中的所有文件?

我想做一些类似于 ls -t的事情,但也包含子目录中的文件。但问题是我不希望输出像 ls -R那样格式化,就像这样:

[test]$ ls -Rt
b       testdir test


./testdir:
a

我希望它的格式像 find命令显示子目录中的文件那样。例如:

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

但是 find似乎没有按照上次更新时间按时间顺序排列结果。

那么,我如何才能列出一个目录和子目录中的所有文件,按照 find的格式,但是按照相反的时间顺序?

300608 次浏览
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

Try this one:

find . -type f -printf "%T@ %p\n" | sort -nr | cut -d\  -f2-

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.

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

try this:

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

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.

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