How to view date of find command result file in bash

I use the find command to search for some files in bash. Everything goes fine, the result shows that I just contain the file name, but not the date the file was last modified. I tried passing it to ls or ls -ltr, but it just doesn't show the filedate column as a result, I also tried this:

ls -ltr | find . -ctime 1 

but actually I did not work. Can you tell me how I can view the filedate files returned by find?

+4
source share
3 answers

For this you need xargs or -exec :

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

(The first executes ls for each found file individually, the second combines them into one or more large ls invocations, so that they can be formatted a little better.)

+6
source

If you want to display output like ls, you can use the -ls to search:

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

If you only need a timestamp, you need to look at the -printf option

 $ find . -name resolv.conf -printf "%a\n" Mon May 21 09:15:24 2012 
+4
source
 find . -ctime 1 -printf '%t\t%p\n' 

prints the datetime and file path separated by .

+2
source

Source: https://habr.com/ru/post/1413476/


All Articles