Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change permissions to certain file pattern/extension?

Using chmod, I do chmod +x *.sh in the current directory but what if I want to change all files including files within subfolders that has an sh file extension?.

chmod +x -R * will work but I need something more like chmod +x -R *.sh

like image 832
ivanceras Avatar asked Nov 22 '10 20:11

ivanceras


People also ask

How do you change file access permissions?

To change file and directory permissions, use the command chmod (change mode). The owner of a file can change the permissions for user ( u ), group ( g ), or others ( o ) by adding ( + ) or subtracting ( - ) the read, write, and execute permissions.

What are 644 permissions?

Permissions of 644 mean that the owner of the file has read and write access, while the group members and other users on the system only have read access. For executable files, the equivalent settings would be 700 and 755 which correspond to 600 and 644 except with execution permission.

How do I change permissions on multiple files in Linux?

To modify the permission flags on existing files and directories, use the chmod command ("change mode"). It can be used for individual files or it can be run recursively with the -R option to change permissions for all of the subdirectories and files within a directory.


2 Answers

use find:

find . -name "*.sh" -exec chmod +x {} \; 
like image 118
ennuikiller Avatar answered Oct 06 '22 15:10

ennuikiller


Try using the glorious combination of find with xargs.

find . -iname \*.sh -print0 | xargs -r0 chmod +x 

The . is the directory to start in, in this case the working directory.

like image 38
Orbling Avatar answered Oct 06 '22 17:10

Orbling