IWETHEY v. 0.3.0 | TODO
1,095 registered users | 1 active user | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Quick bash script help needed
I need to walk through a directory tree and do a 'chmod 774' to anything that is NOT a directory. I have no idea how to do this. As you read this, I am CDing through each directory and doing it by hand...
Hurt me if you must, but let the duckie go!
New 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
New 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
New 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
New 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
Expand Edited by Yendor July 19, 2006, 08:48:28 AM EDT
New 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
New 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]
New '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..."
New 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]
New 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..."
New 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
New 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]
New Thanks.
That did the trick.
Hurt me if you must, but let the duckie go!
     Quick bash script help needed - (inthane-chan) - (12)
         find . -type f -exec chmod 774 '{}' #untested -NT - (ben_tilly) - (11)
             find . -type f -print | xargs chmod 774 #untested/same thing -NT - (Yendor) - (9)
                 Mine is safer (newlines in filenames) -NT - (ben_tilly) - (8)
                     Mine is bigger - (Yendor) - (7)
                         Who uses a newline in a filename? - (ben_tilly) - (6)
                             Why? - (drewk) - (5)
                                 'find' starts a process for each iteration of exec - (admin) - (4)
                                     I don't follow - (drewk) - (3)
                                         Exact opposite. - (admin) - (2)
                                             Not necessarily a *single* string - (ben_tilly)
                                             Okay, makes sense - (drewk)
             Thanks. - (inthane-chan)

Oh good, just go the wrong way why don't you!
112 ms