chgrp -R | chmod +t sticky bit | chown --reference=file2 file1

change the group of documents to editor
user1@ubuntu:~$ chgrp -R editor documents

 Sticky bit can protect these file from deletion. When sticky bit is set, only the owner or a user with root privileges can delete a file.
Additionally, sticky bit works only with directories and is ignored on ordinary files.


user1@ubuntu:~$ chmod +t documents
When user1 creates a file, the default permissions are limited to user1 and its private group (user1) named after the user account. This is the reason user2 sees Permission denied on editing file. By changing the group of documents to editor we allow all members of editor to read and write to files in documents.


To change ownership of a file, use the following command:
$chown newuser filename
To change the owner as well as the group of file, use the following command:
$chown newuser:newgroup filename
You can skip changing owner and change only the group with the following command:
$chown :newgroup filename
Note that the chown command can only be used by users with root privileges.

ubuntu@ubuntu:/home/us1$ ll
total 16
drwxr-xr-x 3 us1  us1group 4096 Dec 11 11:47 ./
drwxr-xr-x 9 root root     4096 Dec 11 11:38 ../
drwxr-xr-- 3 us1  us1group 4096 Dec 11 11:52 us1dir/
-rw------- 1 us1  us1group  608 Dec 11 11:47 .viminfo
ubuntu@ubuntu:/home/us1$ sudo chown ubuntu us1dir/
ubuntu@ubuntu:/home/us1$ ll
total 16
drwxr-xr-x 3 us1    us1group 4096 Dec 11 11:47 ./
drwxr-xr-x 9 root   root     4096 Dec 11 11:38 ../
drwxr-xr-- 3 ubuntu us1group 4096 Dec 11 11:52 us1dir/
-rw------- 1 us1    us1group  608 Dec 11 11:47 .viminfo

ubuntu@ubuntu:/home/us1$ chgrp -R ubuntu us1dir/
ubuntu@ubuntu:/home/us1$ ll us1dir/
total 16
drwxr-xr-- 3 ubuntu ubuntu   4096 Dec 11 11:52 ./
drwxr-xr-x 3 us1    us1group 4096 Dec 11 11:47 ../
-rw-r--r-- 1 us1    ubuntu      8 Dec 11 11:47 file1
drwxrwxrwt 2 us1    ubuntu   4096 Dec 11 11:55 stick/

How to pick owner/group information from a reference file?


chown --reference=[ref-file-name] [filename]
For example:
chown --reference=file2 file1

Comments

Popular posts from this blog

HAproxy logging

teamcity Automatic Agent Start under Linux

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all