dan
dan

Reputation: 45652

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?

Upvotes: 109

Views: 370849

Answers (8)

The_Learner
The_Learner

Reputation: 619

If its ok to use GUI, try nautilus . and then search from the search bar. By default, this search lists all the files in directory and subdirectories. However, sorting in reverse chronological order is not possible.

Upvotes: 0

rashmi
rashmi

Reputation: 1709

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.

Upvotes: 170

Parakleta
Parakleta

Reputation: 1201

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.

Upvotes: 29

Pankaj Tiwari
Pankaj Tiwari

Reputation: 11

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

Upvotes: 1

wfg5475
wfg5475

Reputation: 31

try this:

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

Upvotes: 2

Bobby
Bobby

Reputation: 81

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

Upvotes: 8

marco
marco

Reputation: 4675

Try this one:

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

Upvotes: 59

yankee
yankee

Reputation: 40840

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

Upvotes: 4

Related Questions