A Linux chown command every day

Source: Internet
Author: User

Chown the owner of the specified file to the specified user or group, the user can be either a user name or a user ID; a group can be a group name or a group ID; a file is a space-separated list of files to change permissions, and wildcard characters are supported. System administrators often use the Chown command to give users permission to use a file after copying it to another user's directory.


1. Command format:

chown [Options] ... Owner [: [Group]] file ...

2. Command function:

Change the file owner and group by Chown. You can use the user name and user identification number settings when you change the owner or group of the file. Ordinary users cannot change their files to other owners. Its operation permissions are generally administrators.

3. Command parameters:

Necessary parameters:

-C Displays information about the changed parts

-F Ignore Error messages

-H Fix Symbolic link

-R handles all files in the specified directory and its subdirectories

-V displays detailed processing information

-deference acts on the point of a symbolic link, not the linked file itself

4. Usage examples:

Example 1: Changing the owner and the genus Group

Command:

Chown Centos:centos Text

output:

[BEGIN] 2016/1/4 15:36:58[[EMAIL PROTECTED] ~]# LLTOTAL 76-RW-------.  1  root root  3345 dec 29 21:22 anaconda-ks.cfg-rw-r--r--.  1  Root root     0 jan  3 04:50 ddd.ddd-rw-r--r--.  1  root root    18 jan  3 21:43 dump.rdb-rw-r--r--.   1 root root 39935 dec 29 21:22 install.log-rw-r--r--.  1 root  root  9154 dec 29 21:19 install.log.syslogdrwxr-xr-x. 9 1001  1001  4096 dec 31 00:01 nginx-1.8.0drwxrwxrwx. 6 root root   4096 dec 29 22:33 redis-3.0.6-rw-r--r--.  1 root root      0 jan  3 04:58 testfile-rw-r--r--.  1 root root      0 Jan  3 05:02 testfile1drwxr-xr-x. 6 root root  4096  Jan  3 06:04 text-rw-rw-r--.  1 root root     0  JAN  3 04:48 TEXT.DDD---xr--r--.  1 root root      0 Jan  3 04:43 text.txt   [[email protected] ~]#  CHOWN CENTOS:CENTOS TEXT[[EMAIL PROTECTED] ~]# LLTOTAL 76-RW-------.  1  root   root    3345 Dec 29 21:22  Anaconda-ks.cfg-rw-r--r--.  1 root   root       0  jan  3 04:50 ddd.ddd-rw-r--r--.  1 root   root       18 jan  3 21:43 dump.rdb-rw-r--r--.  1 root    root   39935 Dec 29 21:22 install.log-rw-r--r--.  1 root   root     9154 Dec 29 21:19 install.log.syslogdrwxr-xr-x. 9   1001    1001  4096 dec 31 00:01 nginx-1.8.0drwxrwxrwx. 6 root    root    4096 dec 29 22:33 redis-3.0.6-rw-r--r--.  1 root   root       0 Jan  3  04:58 testfile-rw-r--r--.  1 root   root        0 Jan  3 05:02 testfile1drwxr-xr-x. 6 centos centos   4096 jan  3 06:04 text-rw-rw-r--.  1 root   root        0 JAN  3 04:48 TEXT.DDD---xr--r--.  1 root    root  &Nbsp;    0 jan  3 04:43 text.txt[end] 2016/1/4 15:37:37 


Example 2: Change only the owner

Command:

Chown:centos text

Output:

[BEGIN] 2016/1/4 15:41:02[EMAIL PROTECTED] ~]# LLTOTAL 76-RW-------.  1  root root  3345 dec 29 21:22 anaconda-ks.cfg-rw-r--r--.  1  Root root     0 jan  3 04:50 ddd.ddd-rw-r--r--.  1  root root    18 jan  3 21:43 dump.rdb-rw-r--r--.   1 root root 39935 dec 29 21:22 install.log-rw-r--r--.  1 root  root  9154 dec 29 21:19 install.log.syslogdrwxr-xr-x. 9 1001  1001  4096 dec 31 00:01 nginx-1.8.0drwxrwxrwx. 6 root root   4096 dec 29 22:33 redis-3.0.6-rw-r--r--.  1 root root      0 jan  3 04:58 testfile-rw-r--r--.  1 root root      0&nbsp Jan  3 05:02 testfile1drwxr-xr-x. 6 centos centos  4096 jan   3 06:04 text-rw-rw-r--.  1 root root     0  JAN  3 04:48 TEXT.DDD---xr--r--.  1 root root     0  Jan  3 04:43 text.txt[[email protected] ~]# chown :centos  TEXT.DDD[[EMAIL PROTECTED] ~]# LLTOTAL 76-RW-------.  1 root    Root    3345 dec 29 21:22 anaconda-ks.cfg-rw-r--r--.  1 root    root       0 Jan  3 04:50  Ddd.ddd-rw-r--r--.  1 root   root      18 Jan   3 21:43 dump.rdb-rw-r--r--.  1 root   root   39935  Dec 29 21:22 install.log-rw-r--r--.  1 root   root    9154 dec  29 21:19 install.log.syslogdrwxr-xr-x. 9   1001   1001   4096 Dec 31 00:01 nginx-1.8.0drwxrwxrwx. 6 root    Root    4096 dec 29 22:33 redis-3.0.6-rw-r--r--.  1 root    root       0 Jan  3 04:58  Testfile-rw-r--r--.  1 root   root       0 jan   3 05:02 testfile1drwxr-xr-x. 6 centos centos  4096 jan   3 06:04 text-rw-rw-r--.  1 root   centos      0 JAN  3 04:48 TEXT.DDD---xr--r--.  1 root   root       &nbsP;0 jan  3 04:43 text.txt[end] 2016/1/4 15:41:45 

Description: The original owner is unchanged, only the genus Group is changed. (PS: or change the owner of the master Chown centos:textddd only changes the file)


Example 3: Change the owner and owner group of all files under the specified directory and its subdirectories

Command:

Chown-r-V Root:mail nginx-1.8.0

Output:

[BEGIN] 2016/1/4 15:47:51[[EMAIL PROTECTED] ~]# LLTOTAL 76-RW-------.  1  root   root    3345 Dec 29 21:22  Anaconda-ks.cfg-rw-r--r--.  1 root   root       0  jan  3 04:50 ddd.ddd-rw-r--r--.  1 root   root       18 jan  3 21:43 dump.rdb-rw-r--r--.  1 root    root   39935 dec 29 21:22 install.log-rw-r--r--.  1  root   root    9154 dec 29 21:19  Install.log.syslogdrwxr-xr-x. 9   1001   1001  4096 dec  31 00:01 nginx-1.8.0drwxrwxrwx. 6 root   root     4096 dec 29 22:33 redis-3.0.6-rw-r--r--.  1 root   root       0 jan  3 04:58  testfile-rw-r--r--.  1 root   root       0  jan  3 05:02 testfile1drwxr-xr-x. 6 centos centos  4096  jan  3 06:04 text-rw-rw-r--.  1 root   centos      0 JAN  3 04:48 TEXT.DDD---xr--r--.  1 root    root       0 jan  3 04:43 text.txt[[email  protected] ~]# chown -r -v root:centos nginx-1.8.0changed ownership  of  ' NGINX-1.8.0/OBJS/SRC/HTTP/MODULES/NGX_HTTP_SSL_MODULE.O '  to root:centoschanged  ownership of  ' NGINX-1.8.0/OBJS/SRC/HTTP/MODULES/NGX_HTTP_CHUNKED_FILTER_MODULE.O '  to root: Centoschanged ownership of  ' NGINX-1.8.0/OBJS/SRC/HTTP/MODULES/NGX_HTTP_LOG_MODULE.O '  to root:centoschanged  ownership of  ' NGINX-1.8.0/OBJS/SRC/HTTP/MODULES/NGX_HTTP_GZIP_STATIC_MODULE.O '  to root: centoschanged ownership of  ' NGINX-1.8.0/OBJS/SRC/HTTP/MODULES/NGX_HTTP_EMPTY_GIF_MODULE.O '  to root:centoschanged ownership of  ' Nginx-1.8.0/objs/src/http/modules/ngx_http_range _FILTER_MODULE.O '  to root:centoschanged ownership of  ' nginx-1.8.0/objs/src/http/ MODULES/NGX_HTTP_AUTOINDEX_MODULE.O '  to root:centoschanged ownership of  ' nginx-1.8.0/ OBJS/SRC/HTTP/MODULES/NGX_HTTP_REWRITE_MODULE.O '  to root:centoschanged ownership of  ' NGINX-1.8.0/OBJS/SRC/HTTP/MODULES/NGX_HTTP_FASTCGI_MODULE.O '  to root:centoschanged ownership  of  ' NGINX-1.8.0/OBJS/SRC/HTTP/MODULES/NGX_HTTP_STUB_STATUS_MODULE.O '  to root: centoschanged ownership of ' NGINX-1.8.0/OBJS/SRC/HTTP/MODULES/NGX_HTTP_UPSTREAM_KEEPALIVE_MODULE.O '  to root:centos[[email  protected] ~]#[end] 2016/1/4 15:48:48


A Linux chown command every day

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.