Post #262,089
7/18/06 7:23:06 PM
|
find . -type f -exec chmod 774 '{}' #untested
a very rich person should leave his kids enough to do anything but not enough to do nothing. -- Warren Buffett
|
Post #262,102
7/18/06 10:13:30 PM
|
find . -type f -print | xargs chmod 774 #untested/same thing
-YendorMike
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." - Benjamin Franklin, 1759 Historical Review of Pennsylvania
|
Post #262,119
7/19/06 12:33:25 AM
|
Mine is safer (newlines in filenames)
a very rich person should leave his kids enough to do anything but not enough to do nothing. -- Warren Buffett
|
Post #262,135
7/19/06 8:47:46 AM
7/19/06 8:48:28 AM
|
Mine is bigger
Who the fuck uses a newline in a filename, anywho?
TIMTOWTDI, and all that...
-YendorMike
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." - Benjamin Franklin, 1759 Historical Review of Pennsylvania
Edited by Yendor
July 19, 2006, 08:48:28 AM EDT
|
Post #262,171
7/19/06 1:24:20 PM
|
Who uses a newline in a filename?
Someone with limited permissions who is attempting to get local root access, that's who. :-P
Anyways I was expecting you to come back with the fact that yours is faster. By a lot.
Cheers, Ben
a very rich person should leave his kids enough to do anything but not enough to do nothing. -- Warren Buffett
|
Post #262,177
7/19/06 1:38:24 PM
|
Why?
I'm guessing yours is looping through an array, all of which has to stay in memory simultaneously, while his iterates through a list of files with only one filename|node in memory at a time. Am I close?
===
Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats]. [link|http://DocHope.com|http://DocHope.com]
|
Post #262,180
7/19/06 1:59:11 PM
|
'find' starts a process for each iteration of exec
Whereas the form that Mike used will collect all the filenames, then feed them to chmod at one time.
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #262,182
7/19/06 2:10:48 PM
|
I don't follow
I would expect if I watched top while Ben's is running, I'd see one instance of find and one instance of chmod that would live until everything was done. With Mike's I'd expect to see one instance of find which would finish as soon as the file list is created, and a new instance of chmod would appear for each file.
So if process creation was the bottleneck, I'd expect Mike's to be faster.
===
Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats]. [link|http://DocHope.com|http://DocHope.com]
|
Post #262,183
7/19/06 2:18:33 PM
|
Exact opposite.
find -exec chmod calls 'chmod somefile' for each file it finds. It has to, because it can't know how that particular executable works. In order to keep one around and use it, some sort of piping would be necessary.
find | xargs chmod will instead gather up all the file names, turn them into a single string via xargs, then pass that string as args to chmod. Run 'find . -type f | xargs' sometime to see what it does.
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #262,186
7/19/06 2:22:34 PM
|
Not necessarily a *single* string
xargs will break up long lists so that you fit inside the limits for the length of a command line.
Cheers, Ben
a very rich person should leave his kids enough to do anything but not enough to do nothing. -- Warren Buffett
|
Post #262,187
7/19/06 2:25:44 PM
|
Okay, makes sense
In my limited use of scripting, I must have gotten lucky in that I found piping more clear conceptually than calling -exec or other optional parameters on various commands.
===
Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats]. [link|http://DocHope.com|http://DocHope.com]
|
Post #262,193
7/19/06 3:07:29 PM
|
Thanks.
That did the trick.
Hurt me if you must, but let the duckie go!
|