Question

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?

Was it helpful?

Solution

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.)

OTHER TIPS

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
find . -ctime 1 -printf '%t\t%p\n'

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top