chgrp chgrp (1) - change group ownership
chgrp chgrp (1) - change file group ownership
To demonstrate the change group 'chgrp' command, I like to list the files and directories with the current group ownership first. As you can see from the commands below all files and directories are group owned by 'staff'. I like to change them to group 'root' instead of the group 'staff'. First, I need to know I am in the correct directory before changing the group permssion.
/export/home/wahid/training/OpenSolaris/pkgdir
I see the current direcoty group permission is 'staff'.
total 13
-rw-r--r-- 1 wahid staff 11258 2011-01-03 22:09 pkg-publisher
drwxr-xr-x 2 wahid staff 8 2011-01-15 17:36 text
I want to get a long listing of all files and directories recursively to know the group ownership for all files and directories.
.:
total 13
-rw-r--r-- 1 wahid staff 11258 2011-01-03 22:09 pkg-publisher
drwxr-xr-x 2 wahid staff 8 2011-01-15 17:36 text
./text:
total 3220
-rw-r--r-- 1 wahid staff 2856 2011-01-03 22:04 pkg-info.txt
-rw-r--r-- 1 wahid staff 475569 2011-01-03 23:38 pkg-install-amp.txt
-rw-r--r-- 1 wahid staff 2358 2011-01-03 22:06 pkg-list.txt
-rw-r--r-- 1 wahid staff 4402 2011-01-03 22:01 pkg-search-content.txt
-rw-r--r-- 1 wahid staff 178925 2011-01-03 21:58 pkg-search.txt
-rw-r--r-- 1 root root 2479853 2011-01-03 21:26 pkg.txt
When you use the 'chmod', 'chgown', and 'chgrp' commands, you have to have at least equivalent access
privileges or higher to be able to change the access permission of any file or directory. As shown below, I only
belong to group 'staff', therefore my command 'chgrp root *' failed due to lower group ownership permission.
uid=101(wahid) gid=10(staff) groups=10(staff)
chgrp: changing group of `pkg-publisher': Not owner
chgrp: changing group of `text': Not owner
Now, I switch to 'root' access and since I have higher privileges, I can issue any commands to make any change I desire provided that I do not cause any unexpected access issues.
Password:
Sun Microsystems Inc. Sun OS 5.11 snv_111b November 2008
uid=0(root) gid=0(root)
groups=0(root),1(other),2(bin),3(sys),4(adm),5(uucp),6(mail),7(tty),8(lp),9(nuucp),12(daemon)
Since, I switched to root access with '-' option, I get the root profile exported in my current environment. Therefore, my current working directory is change to '/root' which is the HOME directory for 'root' account. I could have just do the 'su' command witthout the '-' option to keep the environment for user 'wahid' and my current directory would have remained unchanged.
/root
In this case, I change my directory back to where I wanted to be and run the commands below to verify the group ownership before making any changes.
total 13
-rw-r--r-- 1 wahid staff 11258 2011-01-03 22:09 pkg-publisher
drwxr-xr-x 2 wahid staff 8 2011-01-15 17:36 text
At this point, I like to change the group permissino for both of the directories below to group 'root' as shown below:
total 13
-rw-r--r-- 1 wahid root 11258 2011-01-03 22:09 pkg-publisher
drwxr-xr-x 2 wahid root 8 2011-01-15 17:36 text
As you can see from the output of the 'ls -lR *', the files under the text directory are still the same as before. That is because I did not change the group permission for the files recursively.
-rw-r--r-- 1 wahid root 11258 2011-01-03 22:09 pkg-publisher
text:
total 3220
-rw-r--r-- 1 wahid staff 2856 2011-01-03 22:04 pkg-info.txt
-rw-r--r-- 1 wahid staff 475569 2011-01-03 23:38 pkg-install-amp.txt
-rw-r--r-- 1 wahid staff 2358 2011-01-03 22:06 pkg-list.txt
-rw-r--r-- 1 wahid staff 4402 2011-01-03 22:01 pkg-search-content.txt
-rw-r--r-- 1 wahid staff 178925 2011-01-03 21:58 pkg-search.txt
-rw-r--r-- 1 root root 2479853 2011-01-03 21:26 pkg.txt
Now, I like to change all the files and directories recursively with the option of '-R' to group 'root'.
I list the files and directories to see the result of the previous command.
.:
total 13
-rw-r--r-- 1 wahid root 11258 2011-01-03 22:09 pkg-publisher
drwxr-xr-x 2 wahid root 8 2011-01-15 17:36 text
./text:
total 3220
-rw-r--r-- 1 wahid root 2856 2011-01-03 22:04 pkg-info.txt
-rw-r--r-- 1 wahid root 475569 2011-01-03 23:38 pkg-install-amp.txt
-rw-r--r-- 1 wahid root 2358 2011-01-03 22:06 pkg-list.txt
-rw-r--r-- 1 wahid root 4402 2011-01-03 22:01 pkg-search-content.txt
-rw-r--r-- 1 wahid root 178925 2011-01-03 21:58 pkg-search.txt nge
-rw-r--r-- 1 root root 2479853 2011-01-03 21:26 pkg.txt
Since, I was just demonstrating the 'chgrp' command, I will change everything back to original group permission using the 'chgrp' command again, but this time I change the group to 'staff' instead of the 'root'.
total 13
-rw-r--r-- 1 wahid staff 11258 2011-01-03 22:09 pkg-publisher
drwxr-xr-x 2 wahid staff 8 2011-01-15 17:36 text
I verify this change is done correctly.
-rw-r--r-- 1 wahid staff 11258 2011-01-03 22:09 pkg-publisher
text:
total 3220
-rw-r--r-- 1 wahid staff 2856 2011-01-03 22:04 pkg-info.txt
-rw-r--r-- 1 wahid staff 475569 2011-01-03 23:38 pkg-install-amp.txt
-rw-r--r-- 1 wahid staff 2358 2011-01-03 22:06 pkg-list.txt
-rw-r--r-- 1 wahid staff 4402 2011-01-03 22:01 pkg-search-content.txt
-rw-r--r-- 1 wahid staff 178925 2011-01-03 21:58 pkg-search.txt
-rw-r--r-- 1 root staff 2479853 2011-01-03 21:26 pkg.txt
Please click on " man chgrp " to see the Manual Page for this command.