|
|
#1 |
|
League Commissioner
Join Date: Aug 2006
Posts: 5,039
|
Find, xargs, commands
I'm trying to do something really basic, but I just can't seem to get it right. I want to find a bunch of files, and then perform a command on them.
The find criterion is "Creation Date = 1970 1 Jan", so: Code:
find * \! -newerBt 19700102 Code:
SetFile -d "$(GetFileInfo -m ${a})" ${a}
So I tried: Code:
for a in $(find * \! -newerBt 19700102); do SetFile -d "$(GetFileInfo -m ${a})" ${a}; done
When I try replacing the action with "echo", I get the filenames divided by spaces, despite my best efforts to avoid that. I then tried: Code:
for a in $(find * \! -newerBt 19700102 -print0); do xargs -0 echo "$a"; done I tried Code:
find * \! -newerBt 19700102 -print0 | xargs -0 GetFileInfo -m I'm probably making a complete mess of this. I've flicked through some Shell script sample sites to find something similar, but with limited success. Any help greatly appreciated. Last edited by benwiggy; 10-08-2012 at 05:43 AM. |
|
|
|
|
|
#2 |
|
MVP
Join Date: Aug 2009
Posts: 1,119
|
Try this:
Code:
find * \! -newerBt 19700102 -exec SetFile -d "$(GetFileInfo -m {})" {} \;
|
|
|
|
|
|
#3 |
|
League Commissioner
Join Date: Aug 2006
Posts: 5,039
|
Thanks, but I get "ERROR: invalid date/time".
What's weird is that "GetFileInfo -m <file>" works on its own as a command in the Terminal, but as soon as you use wildcards, it doesn't. So "GetFileInfo -m *" doesn't work. |
|
|
|
|
|
#4 |
|
MVP
Join Date: Aug 2009
Posts: 1,119
|
All roads lead to Rome
![]() Code:
find * \! -newerBt 19700102 | while read file; do
echo ${file}
info = `GetFileInfo -m ${file}`
SetFile -d "${info}"
done
|
|
|
|
|
|
#5 | |||||||||||||||||||||||
|
League Commissioner
Join Date: Aug 2006
Posts: 5,039
|
Not all, in this case! usage: GetFileInfo [-P] [-a[<attrib-letter>] | -t | -c | -d | -m] <path> ERROR: invalid date/time I was wondering whether there was a way to do it without the Apple-specific, Xcode-only Apple commands. I can get the date with: Code:
stat -f %Sm -t %Y%m%d |
|||||||||||||||||||||||
|
|
|
|
|
#6 | |||||||||||||||||||||||
|
MVP
Join Date: Apr 2008
Location: Berkeley CA USA
Posts: 1,008
|
You can't put whitespace around the = in an assignment. (I've also replaced backticks with a $( ... ) construct, just because I find it more readable. It's also more flexible, in that $( ... ) can be nested without horrendous quoting.) Plus, you forgot to quote the filename, which might contain whitespace or other shell-meaningful characters. And you left the filename off the SetFile command. Code:
find * \! -newerBt 19700102 | while read file; do echo "$file" info=$(GetFileInfo -m "$file") SetFile -d "$info" "$file" done |
|||||||||||||||||||||||
|
|
|
|
|
#7 |
|
League Commissioner
Join Date: Aug 2006
Posts: 5,039
|
Great. That works just fine.
Thanks. |
|
|
|
|
|
#8 |
|
MVP
Join Date: Aug 2009
Posts: 1,119
|
I typed it from the top of my head.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|