1

I need to store the full path of a specific file found through find (and successive piped operations on find results). I'm using this:

find "$PWD" . -iname p_*.raw -printf "%Tc %p\n" | sort  | cut -f 7 -d " " 

However, as it is it produces shortened file paths "$PWD" doesn't seem to have any effect. Is there any way to force it to show full path?

83ingD33p
  • 13
  • 4
  • 3
    Possible duplicate of [How to recursively list all files with timestamps and full path?](https://superuser.com/questions/228529/how-to-recursively-list-all-files-with-timestamps-and-full-path) – harrymc Nov 08 '19 at 20:20
  • I might have spaces in the folder names. – 83ingD33p Nov 10 '19 at 11:57

1 Answers1

0

Your solution is close.

You are telling find where to look twice, "$PWD" and .. Drop the second one and add a slash to the first. Add quotes around the name pattern as well.

find "$PWD/" -iname "p_*.raw" ....

You might have an issue with the cut command as well, since it's only selecting one field rather than name and time. Still, your attempt is almost there.

Chindraba
  • 1,963
  • 1
  • 11
  • 25
  • This works brilliantly. Although, am not sure what you meant about cut selecting only one field. I do want only one field: the path. – 83ingD33p Nov 10 '19 at 11:56
  • Only one field for only the path is good. The title included the timestamp. You might also consider placing the `sort` after the `cut`, less work for the sort, and sort by the path rather than the first field which is probably the weekday of the time stamp. – Chindraba Nov 10 '19 at 17:03
  • I kept sort first because I wanted to sort by time modified really. For some reason sort with default options gave me the correct order. If I do cut first, I don't think it'll be able to do that. – 83ingD33p Nov 11 '19 at 13:34
  • You are correct. `cut` then `sort` would be in order of path, which I thought was your goal. With timestamp order as the goal it is good as it stands. As a caution for future use, the columns are not _always_ that way. When/if it spits out something weird, drop the `cut` and see what the fields are. For example, field 7 for me is the timezone of the timestamp, not path. – Chindraba Nov 11 '19 at 14:53