Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give 777 permission to multiple directories at a time in unix?

Tags:

linux

shell

unix

I have several sub directories in a root directory. at a time i want to give chmod 777 permission to those directories.

i know individually we can give chmod -r 777 abcd but i want to give permission to those directories which ever i require at a time.

Example :

XYZ -- Parent Directory 

ABCD EGF GHY JHF OIEDF -- These are sub directories.

now i want to give chmod 777 to ABCD EGF GHY . at a time to all these directories.

Thanks in Advance.

like image 733
Dileep Avatar asked Sep 30 '13 11:09

Dileep


People also ask

How do I give permission to all subfolders in Unix?

Changing permissions with chmod 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.

How do I give permission to 777 in Unix?

Cause. The command chmod -R 777 / makes every single file on the system under / (root) have rwxrwxrwx permissions. This is equivalent to allowing ALL users read/write/execute permissions. If other directories such as home, media, etc are under root then those will be affected as well.

Can I chmod multiple files at once?

If you need to change a file permission, use the chmod command. It also allows to change the file permission recursively to configure multiple files and sub-directories using a single command.


1 Answers

Assuming XYZ is the path to the root of your files, you can use globbing to exactly match the files you want:

chmod 777 /XYZ/{ABCD,EGF,GHY}

Then you can use the -R flag to do it recursively on all files and folders contained in these folders.

chmod -R 777 /XYZ/{ABCD,EGF,GHY}

To apply a non-recursive chmod on the 3 folder plus the parent, you can use:

chmod 777 /XYZ/{ABCD,EGF,GHY,}

Note the last comma, to include the directory itself in the globbing

like image 157
Geoffroy Avatar answered Oct 20 '22 00:10

Geoffroy