Farshid
Farshid

Reputation: 5364

How to view file date of result of find command in bash

I use a find command to find some kinds of files in bash. Everything goes fine unlness the result that is shown to me just contains the file name but not the (last modification) date of file. I tried to pipe it into ls or ls -ltr but it just does not show the filedate column in result, also I tried this:

ls -ltr | find . -ctime 1

but actually I didn't work. Can you please guide me how can I view the filedate of files returned by a find command?

Upvotes: 6

Views: 12602

Answers (3)

l0b0
l0b0

Reputation: 58928

find . -ctime 1 -printf '%t\t%p\n'

prints the datetime and file path, separated by a ␉ character.

Upvotes: 2

Bram
Bram

Reputation: 825

If all you want is to display an ls like output you can use the -ls option of find:

$ find . -name resolv.conf -ls
1048592    8 -rw-r--r--   1 root     root          126 Dec  9 10:12 ./resolv.conf

If you want only the timestamp you'll need to look at the -printf option

$ find . -name resolv.conf -printf "%a\n"
Mon May 21 09:15:24 2012

Upvotes: 9

Kilian Foth
Kilian Foth

Reputation: 14376

You need either xargs or -exec for this:

find . -ctime 1 -exec ls -l {} \;

find . -ctime 1 | xargs ls -l

(The first executes ls on every found file individually, the second bunches them up into one ore more big ls invocations, so that they may be formatted slightly better.)

Upvotes: 11

Related Questions