Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux recursive chmod only on sub-directories

Tags:

linux

chmod

I'm on linux, and I have a directory with numerous sub-directories and items inside them. I want to run a recursive chmod on all directories and sub-directories but NONE of the files inside those directories.

chmod -R 777 {folder}

Is there a flag I can add to the chmod command to make the chmod only apply to sub-directories?

like image 535
Sean Avatar asked Apr 03 '12 21:04

Sean


People also ask

Does chmod apply to subdirectories?

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 chmod all files in a directory and subdirectories?

Use chmod -R 755 /opt/lampp/htdocs if you want to change permissions of all files and directories at once. Use find /opt/lampp/htdocs -type d -exec chmod 755 {} \; if the number of files you are using is very large.

How do I make a chmod folder recursive?

It is common to use the basic chmod command to change the permission of a single file. However, you may need to modify the permission recursively for all files within a directory. In such cases, the chmod recursive option ( -R or --recursive ) sets the permission for a directory (and the files it contains).


2 Answers

Off the top of my head:

find {folder} -type d -print0 | xargs -0 chmod 777
like image 94
Philip Kendall Avatar answered Sep 28 '22 23:09

Philip Kendall


find {folder} -type d -print0 | xargs -0 chmod 777

like image 24
quodlibetor Avatar answered Sep 28 '22 21:09

quodlibetor