I am trying to get the latest modification date in a directory tree.
This works fine in terminal:
find . ! -path "*.git*" -exec stat -f "%m" \{} \; | sort -n -r | head -1
But when I try this with NSTask I get
find: -exec: no terminating ";" or "+"
In the args array for NSTask which I am using, I escaped the backslashes:
NSArray *args = @[@".",
@"!",
@"-path",
@"*.git*",
@"-exec",
@"stat",
@"-f",
@"%m",
@"\\{}",
@"\\;",
@"|",
@"sort",
@"-n",
@"-r",
@"|",
@"head",
@"-1"];
So, what am I missing here? I also tried to remove the backslahes all together, but that gave me a “find: |: unknown primary or operator” error.
Thanks for the hints guys. I’ve split it up and get more response now. When running the command without backslashes & without the sort & head I do get results.
So it looks like NSTask should not be fed ‘|’ characters.
I’ll just so the sorting etc. in objc.