$ whatis chown

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

Examples:

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.

$ pwd

/export/home/wahid/training/OpenSolaris/pkgdir

$ id

uid=101(wahid) gid=10(staff) groups=10(staff)

$ ls -l

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 root text

chown: changing ownership of `text': Not owner

So, I switch to root access and keep my current environment for user 'wahid'.

$ su

Password:

As you can see my current working directory remained the same to the directory I was working before I switched user to 'root'

# pwd

/export/home/wahid/training/OpenSolaris/pkg

Again, I list the files before I make any change.

# ls -l

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.

# chown root text

# ls -l

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:

# ls -lR 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- 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

# chown wahid:staff text

Now, I list the files under the 'text' directory to verify this change I just made.

# ls -l 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 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.

# chown -R root:sys text

Now, I list the files under the 'text' directory to verify this change I just made.

# ls -ld text

drwxr-xr-x 2 root sys 8 Jan 15 20:02 text

# ls -l 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'.

# chown -R wahid text

# ls -l text

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

# ls -ld text

drwxr-xr-x 2 wahid sys 8 Jan 15 20:02 text

# pwd

/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'.

# chown -R wahid:staff *

# ls -l

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

# ls -lR

.:

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.

# exit

$ id

uid=101(wahid) gid=10(staff) groups=10(staff)

$ ls -l

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

$ ls -lR

.:

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.


Previous Home Page Next


Contact us      |      About us      |      Term of use      |       Copyright © 2000-2023 MyWebUniversity.com ™