Changing the owner, rights to access to the files and (or) directories in the Linux

June 5, 2016 10 Alex

Sometimes you need to change the permissions on files or folders. This need may arise due to incorrect design of access rights or when fine-tuning of the project on the server. The following describes the commands for changing the rights to access, changing of the owner for the files and (or) folders.

Change owner for all folders and files in a folder

sudo chown -R user:group /path/to/dir/

Where user is new owner, group - new group of user.

-R indicates that the operation must be run recursively.

Changing the permissions to the file or folder

chmod -R 700 /path/to/file/or/dir

-R indicates that the operation must be run recursively.

Changing the permissions only for files

find /path/to/dir -type f -exec chmod 600 {} \;

Changing the permissions only for folders

find /path/to/dir -type d -exec chmod 700 {} \;