How to find all .sh files and make them executable with bash on linux?

also on startup I want to pass the folder path when placing these .sh files

I started with this

#!/bin/bash
find /home/user_name -name "*.sh" 

      

And after the script has to write to the list of logos with executables

+3


source to share


4 answers


By searching directly (I've fixed - this is the safest and preferred option - see comments below):



find /home/user -name "*.sh" -execdir chmod u+x {} +

      

+9


source


If you want to make all files executable for the current user, you can use the command as follows (assuming you have permission to all files in the target home folder):



find /home/user_name -name "*.sh" -print0 | xargs -0 chmod u+x

      

+1


source


another way:

find . -name "*.sh" -exec chmod ux+y {} \;

      

you can check your command first using

find . -name "*.sh" -print

      

+1


source


By @kabanus command

#!/bin/bash

# chmod u+x $(find $1 -name "*.sh")
# ls -1 $1/*.sh
find $1 -name "*.sh" -print -exec chmod u+x {} +

      

And use like

$ ./script.sh /your_directory

      

/your_directory

is the first argument ( $1

) in the script.

-1


source







All Articles