Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Change files only permissions recursively

Q. How do I recursively Change Files with 777 permissions to 755 in /home/user/demo directory? I have a number of files in this directory and I need to change from 777 to only if that file has 777 permissions.

Is there an easy way out to achieve this?

A. To change file access permissions you use chmod command. It has -R or -recursive option that change files and directories recursively. For example

chmod -R 0755 directory


However, if you need to apply conditional file permissions recursively use combination of find and chmod command.

Find all files in /home/user/demo directory
find /home/user/demo -print


Now find all files in /home/user/demo directory with permission 777
find /home/user/demo -perm 777 -print


Next you need to apply chmod on all these files using -exec option:
find /home/user/demo -perm 777 -print -exec chmod 755 {} \;


Read man page of find for more information.

Resources: cyberciti


This post first appeared on Ubuntu Tutorials, please read the originial post: here

Share the post

Change files only permissions recursively

×

Subscribe to Ubuntu Tutorials

Get updates delivered right to your inbox!

Thank you for your subscription

×