+2 votes
in Operating Systems by (71.8k points)

I want to set permissions for a directory and all of its subdirectories to 755. There are several files in those directories too. When I run chmod with option -R, it changes permissions for files too. How can I set permissions to 755 for directories and 644 for files?

1 Answer

+1 vote
by (348k points)
selected by
 
Best answer

You can run the following commands, a combination of find and chmod.

To change permissions to 755 for a directory and its subdirectories, run the following:

find DIRECOTRY_NAME -type d -exec chmod 0755 {} \;

To change permissions to 644 for files, run the following:

find DIRECOTRY_NAME -type f -exec chmod 0644 {} \;

DIRECOTRY_NAME: name of the directory containing subdirectories and files.


...