Linux or UNIX change file permissions recursively ( conditional )
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.
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Linux / UNIX FAQ:
- Linux/UNIX: chmod error
- Can I set the permissions on a symbolic link under Linux/UNIX?
- How Linux file permissions work
- How do I make a Linux or FreeBSD file an executable file?
- Forbidden - You don’t have permission to access this page error and solution
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Please do not use the comment form to ask for help / question. Ask your question on the excellent Linux tech support forum. Thank you very much for stopping by our site!
~ Last updated on: December 28, 2006


Recent Comments
Today ~ 17 Comments
Today ~ 2 Comments
Today ~ 37 Comments
Today ~ 46 Comments
Yesterday ~ 2 Comments