chown chown (1) - change file owner and group
chown chown (1) - change file ownership
chown chown (1b) - change owner
chown chown (2) - change owner and group of a file
As you can see from the above description of what the 'chown' command do, the command 'chown', can be used to change the ownership of files and directories as well as change the group permission of files and directories as desired.
Before running any 'chown' command, I like to list the current working directory, identify the current user, and list the current files and directories access permissions.
/export/home/wahid/training/OpenSolaris/pkgdir
uid=101(wahid) gid=10(staff) groups=10(staff)
total 13
-rw-r--r-- 1 wahid staff 11258 2011-01-03 22:09 pkg-publisher
drwxr-xr-x 2 wahid root 8 2011-01-15 20:02 text t
Now, I will attempt to change the ownership of the 'text' directory, but I am given eotrror 'Not owner' which is true.
chown: changing ownership of `text': Not owner
So, I switch to root access and keep my current environment for user 'wahid'.
Password:
As you can see my current working directory remained the same to the directory I was working before I switched user to 'root'
/export/home/wahid/training/OpenSolaris/pkg
Again, I list the files before I make any change.
total 26
-rw-r--r-- 1 wahid staff 11258 Jan 3 22:09 pkg-publisher
drwxr-xr-x 2 wahid root 8 Jan 15 20:02 text
No w, I change the ownership of the directory 'text' to user 'root' and list them to verify the change I made.
total 26
-rw-r--r-- 1 wahid staff 11258 Jan 3 22:09 pkg-publisher
drwxr-xr-x 2 root root 8 Jan 15 20:02 text
At this time, I list the subdirectories and files permissin first, and then change the ownership and group permssion for all files and directories to 'wahid' and 'staff' using the two commands below:
text:
total 6440
-rw-r--r-- 1 wahid staff 2856 Jan 3 22:04 pkg-info.txt
-rw-r--r-- 1 wahid staff 475569 Jan 3 23:38 pkg-install-amp.txt
-rw-r--r-- 1 wahid staff 2358 Jan 3 22:06 pkg-list.txt
-rw-r--r-- 1 wahid staff 4402 Jan 3 22:01 pkg- the -content.txt
-rw-r--r-- 1 wahid staff 178925 Jan 3 21:58 pkg-search.txt
-rw-r--r-- 1 root staff 2479853 Jan 3 21:26 pkg.txt
Now, I list the files under the 'text' directory to verify this change I just made.
total 6440
-rw-r--r-- 1 wahid staff 2856 Jan 3 22:04 pkg-info.txt
-rw-r--r-- 1 wahid staff 475569 Jan 3 23:38 pkg-install-amp.txt
-rw-r--r-- 1 wahid staff 2358 Jan 3 22:06 pkg-list.txt
-rw-r--r-- 1 wahid staff 4402 Jan 3 22:01 pkg-search-content.txt
-rw-r--r-- 1 wahid staff 178925 Jan 3 21:58 pkg-search.txt
-rw-r--r-- 1 root staff 2479853 Jan 3 21:26 pkg.txt
Here, I am changing all files and directories under the 'text' directory recursively to 'root' as owner and
'sys' as group.
Now, I list the files under the 'text' directory to verify this change I just made.
drwxr-xr-x 2 root sys 8 Jan 15 20:02 text
total 6440
-rw-r--r-- 1 root sys 2856 Jan 3 22:04 pkg-info.txt
-rw-r--r-- 1 root sys 475569 Jan 3 23:38 pkg-install-amp.txt
-rw-r--r-- 1 root sys 2358 Jan 3 22:06 pkg-list.txt
-rw-r--r-- 1 root sys 4402 Jan 3 22:01 pkg-search-content.txt
-rw-r--r-- 1 root sys 178925 Jan 3 21:58 pkg-search.txt
-rw-r--r-- 1 root sys 2479853 Jan 3 21:26 pkg.txt
Now, I change the ownership of the directory 'text' and it's files and directories to 'wahid'.
total 6440
-rw-r--r-- 1 wahid sys 2856 Jan 3 22:04 pkg-info.txt
-rw-r--r-- 1 wahid sys 475569 Jan 3 23:38 pkg-install-amp.txt
-rw-r--r-- 1 wahid sys 2358 Jan 3 22:06 pkg-list.txt
-rw-r--r-- 1 wahid sys 4402 Jan 3 22:01 pkg-search-content.txt
-rw-r--r-- 1 wahid sys 178925 Jan 3 21:58 pkg-search.txt
-rw-r--r-- 1 wahid sys 2479853 Jan 3 21:26 pkg.txt
drwxr-xr-x 2 wahid sys 8 Jan 15 20:02 text
/export/home/wahid/training/OpenSolaris/pkgdir
Now, I change all files and directories under the current working directory 'pkgdir' to owner of 'wahid' and group of 'staff'.
total 26
-rw-r--r-- 1 wahid staff 11258 Jan 3 22:09 pkg-publisher
drwxr-xr-x 2 wahid staff 8 Jan 15 20:02 text
.:
total 26
-rw-r--r-- 1 wahid staff 11258 Jan 3 22:09 pkg-publisher
drwxr-xr-x 2 wahid staff 8 Jan 15 20:02 text
./text:
total 6440
-rw-r--r-- 1 wahid staff 2856 Jan 3 22:04 pkg-info.txt
-rw-r--r-- 1 wahid staff 475569 Jan 3 23:38 pkg-install-amp.txt
-rw-r--r-- 1 wahid staff 2358 Jan 3 22:06 pkg-list.txt
-rw-r--r-- 1 wahid staff 4402 Jan 3 22:01 pkg-search-content.txt
-rw-r--r-- 1 wahid staff 178925 Jan 3 21:58 pkg-search.txt
-rw-r--r-- 1 wahid staff 2479853 Jan 3 21:26 pkg.txt
I exit out of the 'root' access and list the files to verify the change was made correctly.
uid=101(wahid) gid=10(staff) groups=10(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 20:02 text
.:
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 20:02 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 wahid staff 2479853 2011-01-03 21:26 pkg.txt
Please click on " man chown " to see the Manual Page for this command.