What version of fd are you using?
[fd 8.1.1]
How would I get the last modified file in a directory and it sub-directories with fd?
This is the script I have now: ls -t **/*.re | head -n1. It search for files by an extension recursively and returns the last modified file.
I can't get this to run in fd. This is as close as I am:
> fd -e re --exec stat | sort -nr | cut -d: -f2- | head -1
06:29 2020" "Aug 10 10:06:29 2020" "Aug 10 10:06:29 2020" "Aug 9 18:12:28 2020" 4096 8 0 src/Router.re
Great Project.
Thank you.
How about:
fd -e re --exec stat --printf='%Y\t%n\n' | sort -nr | head -1 | cut -f2
I think that I forgot to mention that I am trying this on fishshell. Just started using it. Syntax might be a bit different.
Getting:
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]
stat: illegal option -- -
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]
stat: illegal option -- -
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]
What OS are you on? Your stat options look very different than mine (on linux). I'd read the manpage for your stat, and see how you can use a format that has the timestamp as a single number (unix epoch) and filename.
โฏ sw_vers
ProductName: Mac OS X
ProductVersion: 10.15.6
BuildVersion: 19G73
You read the man page for mac? That is a nice reflex. Thank you for sharing that with me. This man page has some good info it. I will come back and post once i have figured it out. Peace/Love @tmccombs
I think it would be stat -f "%m%t%N" or possibly stat -f "%Sm%t%N" -t %s
fd -e re --exec stat -f "%m%t%N" | sort -nr | head -1 | cut -f2 is correct. You are the lucky winner of my gratitude.
Seriously, you are very generous.
I am still going to take time to study that man page.
Peace/Love