Recursively Change File or Directory Owner on Linux

0

Directory ownership is something that often needs to be changed when an application requires read or write permissions for a directory. This can be a bit tricky to get right at times, but generally you can achieve everything you want using a chown command.

Chown is used to change the ownership of a directory from one user to another. You can perform this action recursively which means you can change the permissions of a directory and all sub directories within it. This is incredibly handy when you have a large directory.

A common use for this is if you have a website directory and you want to use a file manager to be able to perform crud operations on files stored in the directory. For this you will need to give Apache permissions to access the folder. Changing the ownership of the directory to Apache is probably the best solution for this.

To change the ownership of a directory to another user you can execute the following recursive command. If you don’t want this command to be recursive then you can remove the “-R” from the command and it will only apply to the file or folder you define in the path.

This will change the ownership for all files and folders within “/var/www/website”.

chown -R apache /var/www/website

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.