chown chgrp chmod

来源:互联网 发布:剑三明教脸型数据 编辑:程序博客网 时间:2024/04/28 13:14

chown

Name

chown - change file owner and group

Synopsis

chown [OPTION]… [OWNER][:[GROUP]] FILE…
chown [OPTION]… –reference=RFILE FILE…

Description

chown changes the user and/or group ownership of each given file. If only an owner (a user name or numeric user ID) is given, that user is made the owner of each given file, and the files’ group is not changed. If the owner is followed by a colon and a group name (or numeric group ID), with no spaces between them, the group ownership of the files is changed as well. If a colon but no group name follows the user name, that user is made the owner of the files and the group of the files is changed to that user’s login group. If the colon and group are given, but the owner is omitted, only the group of the files is changed; in this case, chown performs the same function as chgrp. If only a colon is given, or if the entire operand is empty, neither the owner nor the group is changed.

 chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID;组可以是组名或者组ID;文件是以空格分开的要改变权限的文件列表,支持通配符。系统管理员经常使用chown命令,在将文件拷贝到另一个用户的名录下之后,让用户拥有使用该文件的权限。

  1.命令格式:

    chown [选项]… [所有者][:[组]] 文件…

  2.命令功能:

   通过chown改变文件的拥有者和群组。在更改文件的所有者或所属群组时,可以使用用户名称和用户识别码设置。普通用户不能将自己的文件改变成其他的拥有者。其操作权限一般为管理员。

  3.命令参数:

  必要参数:
    -c 显示更改的部分的信息
    -f 忽略错误信息
    -h 修复符号链接
    -R 处理指定目录以及其子目录下的所有文件
    (-recursive
operate on files and directories recursively)
    -v 显示详细的处理信息
   -deference 作用于符号链接的指向,而不是链接文件本身

  选择参数:
    –reference=<目录或文件> 把指定的目录/文件作为参考,把操作的文件/目录设置成参考文件/目录相同拥有者和群组
    –from=<当前用户:当前群组> 只有当前用户和群组跟指定的用户和群组相同时才进行改变
    –help 显示帮助信息
    –version 显示版本信息

Examples

chown root /usr Change the owner of /u to “root”.
chown root:staff /usr Likewise, but also change its group to “staff”.
chown -hR root /usr Change the owner of /u and subfiles to “root”.
chown -R abu:sales /home/account/ This is going to make all files inside /home/account/ and its subdirectories to belong to abu and to be associated with the group sales. -R means include all subdirectories

http://linux.die.net/man/1/chown
http://www.cnblogs.com/peida/archive/2012/12/04/2800684.html

chgrp

chgrp:改变用户所属组 change group
chgrp - change group ownership
常用参数-R:修改指定目录下所有的文件和文件夹

示例:
将1.txt的所属组改为test chgrp -R test 1.txt
chgrp staff /usr/db Change the group of /u to “staff”.
chgrp -hR staff /usr/db Change the group of /u and subfiles to “staff”.
chgrp marketing file.txt to change the group specified to a certain document
chgrp oracle /usr/database to change the group specified to a certain directory
chgrp -R marketing /sales/2008 to change the group specified to a certain directory recursively

chmod

chmod : to change the permissions of a file or directory. Use ls -l to see the permission settings.
常用参数-R:修改指定目录下所有的文件和文件夹

ls -l

chmod

rwx rwx rwx = 111 111 111
rw- rw- rw- = 110 110 110
rwx — — = 111 000 000

and so on…

rwx = 111 in binary = 7
rw- = 110 in binary = 6
r-x = 101 in binary = 5
r– = 100 in binary = 4
(A hyphen in any position means that you don’t have that particular permission.)

777 (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
755 (rwxr-xr-x) The file’s owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
700 (rwx——) The file’s owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.

Who

The “who” is a list of letters that specifies whom you’re going to be giving permissions to. These may be specified in any order.

u The **u**ser who owns the file
g The **g**roup the file belongs to.
o The **o**ther users
a **a**ll of the above (an abbreviation for ugo)

Permissions

Of course, the permissions are the same letters that you see in the directory listing:

r Permission to **r**ead the file.
w Permission to **w**rite (or delete) the file.
x Permission to e**x**ecute the file, or, in the case of a directory, search it.

Example

First, let’s prevent outsiders from executing archive.sh
Before: -rwxr-xr-x archive.sh
Command: chmod o=r archive.sh
After: -rwxr-xr– archive.sh

Take away all permissions for the group for topsecret.inf We do this by leaving the permissions part of the command empty.
Before: -rw-r—– topsecret.inf
Command: chmod g= topsecret.inf
After: -rw——- topsecret.inf

Open up publicity.html for reading and writing by anyone.
Before: -rw-r–r– publicity.html
Command: chmod og=rw publicity.html
After: -rw-rw-rw- publicity.htm

=

chmod go=rx wordmatic chmod a=rwx calcmatic

- remove permission

chmod go-w wordmatic

+ add permission

chmod a+wx calcmatic

copy permission

chmod g=u info.dat (“the group is assigned (=) the permissions currently held by the user)

very detailed explanation: https://linuxfrombeginning.wordpress.com/2008/09/25/linux-command-9-chown-chgrp-chmod/
http://linux.die.net/man/1/chmod

0 0
原创粉丝点击