Mass ownership and permission change – Linux – Find command

I want to change the permission and ownership of all files under a particular directory! The directory itself has 1000+ files and folders! Is it possible? Is there any simple way to change that?

Yeah, it can be done by using Find command from commandline in Linux. The find command itself has a wide range of applications. We already discussed the detailas about find command and its different switches. Please read this section for more information >> Find command, switches and examples <<

Find command is one of the best search tool under UNIX/LINUX. There are a lot of options available with find command. This command is very useful in bash scripting also.

How to change the permission of files and folders?

Use chmod along with -exec to change the permissions.

# find ./ -type f  -exec chmod 777 {} \;

this command changes all files permission to 777 in PWD.

Use “-type d” for directory!

How to change ownership?

That’s simple. Use the chown command within the -exec to change the ownership as you wish.

# find ./ -type f  -exec chown images. {} \;

Where “images” is the user and group name.


Read More:

1, 10+ Commonly using OpenVZ commands and its usages
2, How to exclude a directory or multiple directories using find command?
3, How to check spamming on server which has Exim as MTA

Arunlal Ashok

DevOps (Server & Cloud infrastructure) Engineer. I'm dealing Linux servers since 2012. I started this blog to share and discuss my ideas. Always happy for an open discussion! Write to arun (@) crybit (dot) com

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *