bash 如何在linux中使用bash查找所有.sh文件并使它们可执行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44798121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:14:54  来源:igfitidea点击:

How to find all .sh files and make them executable using bash in linux?

linuxbash

提问by ASdsdgf

also when I launch I want to pass path to folder when located these .sh files

同样,当我启动时,我想在找到这些 .sh 文件时将路径传递给文件夹

I started with this

我从这个开始

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

And after script has to write in logo list with executable files

并且在脚本必须用可执行文件写入徽标列表之后

回答by kabanus

Through find directly (I've been corrected- this is safest and preferred - see comments below):

通过直接查找(我已得到纠正-这是最安全和首选的-请参阅下面的评论):

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

回答by Akif

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

如果你想让当前用户的所有文件都可以执行,你可以使用如下命令(假设你对目标主文件夹中的所有文件都有权限):

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

回答by mbieren

another way :

其它的办法 :

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

you can first check your command by using

您可以首先使用以下命令检查您的命令

find . -name "*.sh" -print

回答by zombic

By @kabanus command

通过@kabanus 命令

#!/bin/bash

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

And use as

并用作

$ ./script.sh /your_directory

/your_directory- first argument ($1) in the script.

/your_directory-$1脚本中的第一个参数 ( )。