开发者

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

开发者 https://www.devze.com 2023-02-09 00:06 出处:网络
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:

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?


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.


Try this one:

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


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.


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


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:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消