[Solved] apply 755 mode recursively

I have folders like as below format. I need to apply the 755 mode for '.sh' format only. I am using the below command to apply the changes. But it's affecting first level only. How to apply the changes recursively in .sh file only?

Please suggest the command.
Thanks

 
chmod 755 -R *.sh
 
root_folder/A/
 one.sh
 one.txt
 
root_folder/A/A1
 one.sh
 one.txt
 
root_folder/A/A1/A2
 one.sh
 one.txt
 
find DIR -name '*.sh' | xargs chmod 755
1 Like

Suppose if �root_folder/A/A1/A2' folder doesn't have the *.sh file.
I got the chmod utility usage in console, that's affect, my script.
How to avoid this error even if *.sh file doesn't having the folder.
I wish to execute the chmod command when *.sh file exists the path.

Thanks,

I note a lot of people use xargs (quite useful)... however, the find command has a -exec option which seems to not be very popular (I use it all the time :cool:)

find DIR -name '*.sh' -exec chmod 755 {} \;

Food for thought.

1 Like

Say if there are 10 .sh files under the directory DIR, the above find command will be executed 10 times in total and gives the output to chmod command each time its executed. Whereas if we use xargs along with find, the find command is executed only once ,outputs the 10 files names to xargs and xargs takes the job of appending the file to chmod. So we save the number of processes run thereby reducing the execution time. If we have many number of files under a directory then xargs would be a better option.

I'm not convinced that in today's world of fast CPU's that this is overly important, but I do concede the point with respect to the total number of processes. The main advantage of using the -exec option is that I never have to remember to include the -print0 and -0 options to handle files with white spaces in the name...

To each his own I guess.

It is. The more and more CPU speed we have, the more and more wasteful programmers get, so it about balances out. If you can write just a little better, you can get really big gains.

I believe you are confusing programming versus what is a maintenance command... I agree that programming is getting lax, no doubt, as software gets more and more bloated over time ( I use a numerical finite difference program that has doubled in size over the past five years... :frowning: )

However, The problem has nothing to do with software bloat, but rather ease of use versus a minor inconvenience of cpu time (which does not really affect the "end" user). Take a good look at any servers stats and you'll find it spends a lot of time idle. I would argue that as I type at the keyboard, I'm using less than 1% of one core out of six, with the other 5 cores being used up for a simulation I'm currently running (dynamic flow simulation)... I just ran my command over 10k of my simulation files in over 400 directories. It returned in ~5 seconds versus the ~2 seconds for the xarg version. So my point is... does 3 seconds really make a difference, particularly in the context of this thread?

I was asking why there seems to be a resistance to use built-in options for find where no bias should be found. xargs is a great and useful tool and if you actually issue command and wait for them, then I'd think the 3 seconds *may* be time saving... In my case, I tend to push command into the background, so I actually don't see a time savings at all (from the perception of my minds eye).

As for the 3 seconds, I think I waste more time lifting my cup of coffee... but then again, I do tend to drink slowly :stuck_out_tongue:

Again, food for thought (or is it coffee?)

The difference between running chmod 75,000 times and running chmod 750 times is not "minor".

Unless you install Wordpress. After that, any bit of extra CPU you can squeeze out is precious. :stuck_out_tongue: (Adding one instance to a well-populated server bloated it from <0.1 avg load on PIII-600 to >.3 avg load on P4-2800!) IOW these tranquil conditions, while nice, shouldn't be assumed, lest you be the thing that makes them not true...

Also imagine using an expensive licensed OS where time literally is money, whether you're using the time or not. Wouldn't you want to extract as much work for the money as you could get? Many such servers operate under max loads continually.

Congratulations on your 6 cores, if I had so much CPU time sitting idle I might try farming it out for something else...

A greater than 100% difference in performance sounds significant to me. Under a machine less fantastic than yours, the difference could easily become tedious.

Eh? You've proven yourself there's a difference, and obviously know why.

P.S: If you have -print0, try \+ instead of \; to get all the benefits of find+xargs without all the typing.