PDA

View Full Version : [BASH] Report date modified when using 'find'



altonbr
July 30th, 2008, 12:56 PM
I have a list of absolute directories I created using find and I need to know the date modified for each folder.

I tried replacing "\n" with " " and piping to 'ls -l' but that didn't work. 'ls -l', when I copied the result of
cat /list | tr "\n" " " seemed to list the files in each directory and not the modification date of each folder, so I don't think 'ls' is the command I am looking for.

What else can I use? I noticed 'find' has "modified in the last _n_ days" but I need to know the exact date.

Thank you for your time!

ghostdog74
July 30th, 2008, 12:59 PM
you can use stat to find modification date


stat -c "%y" dir_to_check

altonbr
July 30th, 2008, 01:20 PM
you can use stat to find modification date


stat -c "%y" dir_to_check


As always, thank you for your quick response!

Is there any way to pipe a directory list to stat? Such as 'find' or 'ls'?

Secondly, is there any way for it to print the directory name and then the modification date for each folder? Having a whole slew of modification dates with no folder name is difficult to read.

dwhitney67
July 30th, 2008, 01:25 PM
Extending ghostdog74's suggestion, try:

$ find . -type d -exec stat -c "%n - %y" {} \;

ghostdog74
July 30th, 2008, 01:29 PM
another way, without stat


find . -type d -printf "%t:%p\n"

check the man page of find to see what printf and it format specifiers mean.