如何将目录和子目录中的所有文件按时间倒序排列?

时间:2022-07-23 15:05:18

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:

我想做一些类似ls -t的事情,但也有包含子目录中的文件。但问题是,我不想要像ls -R那样的输出形式,它是这样的:

[test]$ ls -Rt
b       testdir test

./testdir:
a

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

我希望它被格式化,就像find命令在子目录中显示文件一样。即:

[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?

那么,我如何将目录和子目录中的所有文件,以查找的格式列出,而是按照时间倒序排列呢?

7 个解决方案

#1


27  

Try this one:

试试这个:

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

#2


55  

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

ls -lR是在主目录ls -lR |中显示所有文件、目录和子目录,用于显示流中的所有文件。

#3


6  

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.

如果您想要查看的文件数量符合最大参数限制,那么您可以使用globbing来获得您想要的内容,如果您有globstar支持,则可以使用递归。

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

确切地说,2层深度使用:ls -d * */*。

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

使用globstar,用于递归使用: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.

ls的-d参数告诉它不要递归作为参数传递的目录(因为您使用的是shell globbing来执行递归)。这将防止ls使用其递归格式。

#4


3  

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

缺点:只对一定数量的文件有效。如果你有大量的文件,你需要更复杂的文件。

#5


2  

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

试着找到。- d类型或发现。类型d - ls

#6


1  

try this:

试试这个:

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

#7


1  

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

wfg5475的答案是正确的,只需要添加一个东西来显示目录和子目录中的文件:

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

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

添加一件事:从清单输出中忽略所有目录。

#1


27  

Try this one:

试试这个:

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

#2


55  

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

ls -lR是在主目录ls -lR |中显示所有文件、目录和子目录,用于显示流中的所有文件。

#3


6  

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.

如果您想要查看的文件数量符合最大参数限制,那么您可以使用globbing来获得您想要的内容,如果您有globstar支持,则可以使用递归。

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

确切地说,2层深度使用:ls -d * */*。

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

使用globstar,用于递归使用: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.

ls的-d参数告诉它不要递归作为参数传递的目录(因为您使用的是shell globbing来执行递归)。这将防止ls使用其递归格式。

#4


3  

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

缺点:只对一定数量的文件有效。如果你有大量的文件,你需要更复杂的文件。

#5


2  

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

试着找到。- d类型或发现。类型d - ls

#6


1  

try this:

试试这个:

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

#7


1  

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

wfg5475的答案是正确的,只需要添加一个东西来显示目录和子目录中的文件:

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

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

添加一件事:从清单输出中忽略所有目录。