Tuesday, September 13, 2011

Chown & Chgrp command in linux.


The chown command is used to change file or directory ownership.

Here, in the below example.We have changed owner 'tclark' with 'abe' for file 'gettysburg.txt'

# ls -l

total 12
-rw-rw-r– 1 tclark authors 2229 Jan 13 21:35 declaration.txt
-rw-rw-r– 1 tclark authors 1310 Jan 13 17:48 gettysburg.txt
-rw-rw-r– 1 tclark authors 360  Jan 13 17:48 preamble.txt

# chown abe gettysburg.txt

# ls -l

total 12
-rw-rw-r– 1 tclark authors 2229 Jan 13 21:35 declaration.txt
-rw-rw-r– 1  abe   authors 1310 Jan 13 17:48 gettysburg.txt
-rw-rw-r– 1 tclark authors 360  Jan 13 17:48 preamble.txt

The chgrp command is used to change the group with which a file is associated.

Here in the below example.We have changed the group 'tclark' with 'author' for file 'examples'

#ls -l

total 4
-rw-rw-r– 1 tclark tclark 0 Jan 13 21:13 example1.fil
-rw-rw-r– 1 tclark tclark 0 Jan 13 21:13 example2.xxx
drwxrwxr-x 2 tclark tclark 4096 Jan 13 21:35 examples

#chgrp authors examples

# ls -l

total 4
-rw-rw-r– 1 tclark tclark 0 Jan 13 21:13 example1.fil
-rw-rw-r– 1 tclark tclark 0 Jan 13 21:13 example2.xxx
drwxrwxr-x 2 tclark authors 4096 Jan 13 21:35 examples

Enjoy:-)

No comments: