4

I want to recursively list all files in a given directory, with their full path and their timestamps. Something like this:

10:30 Dec 10 2010 /tmp/mydir/myfile

I've tried with:

find . -type f -exec ls -la {} \;

but that doesn't give me the full path.

4 Answers 4

1

And another way to do it if your find doesn't support printf

find . -type f | xargs ls -al  | awk -v pwd="$PWD" '{ print $(NF-2), $(NF-1) , pwd substr($(NF), 2)}'  

Note: This only works as long as there aren't any spaces in the filenames. Output looks like this:

2010-09-29 22:08 /home/nifle/ac.txt
2010-10-04 16:02 /home/nifle/array.sh
2010-10-05 23:32 /home/nifle/b.txt
2010-12-15 16:49 /home/nifle/barcopy/subbar/ghut
2010-12-15 16:48 /home/nifle/bardir/subbar/ghut
2010-09-29 22:16 /home/nifle/foo.gz
2010-09-29 22:16 /home/nifle/foo1.gz
2
  • 1
    As long as there aren't any spaces in the filenames. Jan 3, 2011 at 12:07
  • @Dennis - Ahh, yes you definitely have a point there.
    – Nifle
    Jan 3, 2011 at 12:10
8

Solution 1 (ls)

Run ls on each file and filter the result:

find "$PWD" -type f -exec ls -la {} \; | cut -d ' ' -f 6-

Output:

Jun 14 00:02 /tmp/superuser.com/questions/370070/bar
Jun 14 20:24 /tmp/superuser.com/questions/228529/file  with    multiple   spaces
Jan  2  1972 /tmp/superuser.com/questions/228529/old_file

Solution 2 (-printf)

Use -printf:

find "$PWD" -type f -printf "%t %p\n"

Output:

Thu Jun 14 00:02:47.0173429319 2012 /tmp/superuser.com/questions/370070/bar
Thu Jun 14 20:24:16.0947808489 2012 /tmp/superuser.com/questions/228529/file  with    multiple   spaces
Sun Jan  2 03:04:05.0000000000 1972 /tmp/superuser.com/questions/228529/old_file

Solution 3 (stat)

Run GNU stat on each file:

find "$PWD" -type f -exec stat --format '%y %n' {} \;

Output:

2016-03-30 04:32:10.034718786 +0300 /etc/passwd
2015-12-21 19:30:07.854470768 +0200 /etc/group

Tip: if you have GNU find, \; can be replaced with \+.

3
  • You can replace $PWD with .. Jan 3, 2011 at 12:08
  • @Dennis Williamson: the command from the question already uses . instead of $PWD and it doesn't give him the full path. Jan 3, 2011 at 21:09
  • Ah, sorry, you are correct. Jan 3, 2011 at 21:23
0

This question on StackOverflow plays around with one part of your question. In order to get what you want, you could try the following:

find $ABSOLUTE_PATH_TO_DIR -ls
0

tree is a nice alternative:

tree -fD --timefmt %c

Format the time using strftime syntax.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .