CentOS

Bagaimana Untuk Tukar Owner Pada File/ Direktori Dalam CentOS

Use the chown command to change file owner and group information. Use the chmod command to change file access permissions such as read, write, and access.

chown command

chown command changes the user and/or group ownership of for given file. The syntax is:

chown owner-user file
chown owner-user:owner-group file
chown owner-user:owner-group directory
chown options owner-user:owner-group file

Examples

First, list permissions for demo.txt, enter:

ls -l demo.txt

Sample outputs:

-rw-r--r-- 1 root root 0 Aug 31 05:48 demo.txt

In this example change file ownership to vivek user and list the permissions, run:

chown vivek demo.txt
ls -l demo.txt

Sample outputs:

-rw-r--r-- 1 vivek root 0 Aug 31 05:48 demo.txt

In this next example, the owner is set to vivek followed by a colon and a group onwership is also set to vivek group, run:

chown vivek:vivek demo.txt
ls -l demo.txt

Sample outputs:

-rw-r--r-- 1 vivek vivek 0 Aug 31 05:48 demo.txt

In this example, change only the group of file. To do so, the colon and following GROUP-name ftp are given, but the owner is omitted, only the group of the files is changed:

chown :ftp demo.txt
ls -l demo.txt

Sample outputs:

-rw-r--r-- 1 vivek ftp 0 Aug 31 05:48 demo.txt

Please note that if only a colon is given, or if NEW-OWNER is empty, neither the owner nor the group is changed:

chown : demo.txt

In this example, change the owner of /foo to “root”, execute:

chown root /foo

Likewise, but also change its group to “httpd”, enter:

chown root:httpd /foo

Change the owner of /foo and subfiles to “root”, run:

chown -R root /u

Where,
-R – Recursively change ownership of directories and their contents.

Source: http://www.cyberciti.biz/faq/how-to-use-chmod-and-chown-command/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s