2- 设置文件的权限及归属
2016.6.9
设置文件的权限chmod
格式1
- chomd [ugoa] [+-=] [rwx] 文件...
格式2
- chmod nnn 文件...
[root@test1 dev]# chmod --help
Usage: chmod [OPTION]... MODE[,MODE]... FILE...
or: chmod [OPTION]... OCTAL-MODE FILE...
or: chmod [OPTION]... --reference=RFILE FILE...
Change the mode of each FILE to MODE.
-c, --changes like verbose but report only when a change is made
--no-preserve-root do not treat `/' specially (the default)
--preserve-root fail to operate recursively on `/'
-f, --silent, --quiet suppress most error messages
-v, --verbose output a diagnostic for every file processed
--reference=RFILE use RFILE's mode instead of MODE values
-R, --recursive change files and directories recursively
--help display this help and exit
--version output version information and exit
Each MODE is of the form `[ugoa]*([-+=]([rwxXst]*|[ugo]))+'.
Report chmod bugs to [email protected]
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'chmod invocation'
[root@test1 dev]#
octal [oc·tal || 'ɑktl /'ɒktl]
adj. 八进制的, 以八为基础, 以八为基础的 (计算机, 电子学用语)
设置文件的权限chmod
示例1:调整mymkdir文件的权限,为属主用户添加执行权限,删除其他用户的读取权限
示例2:将mymkdir文件的访问权限设置位“rwxr-xr-x”
示例1:
[root@test1 jason]# mkdir learn
[root@test1 jason]# ls
learn
[root@test1 jason]# cd learn
[root@test1 learn]# touch mymkdir
[root@test1 learn]# ls
mymkdir
[root@test1 learn]# ll
total 0
-rw-r--r-- 1 root root 0 Jun 9 10:27 mymkdir
[root@test1 learn]# chmod u+x,o-r mymkdir
[root@test1 learn]# ll
total 0
-rwxr----- 1 root root 0 Jun 9 10:27 mymkdir
[root@test1 learn]#
示例2:
添加要求权限方法一:
[root@test1 learn]# chmod u=rwx,g=rx,o=rx mymkdir
[root@test1 learn]# ll
total 0
-rwxr-xr-x 1 root root 0 Jun 9 10:27 mymkdir
[root@test1 learn]#
去掉所有权限
[root@test1 learn]# chmod 000 mymkdir
[root@test1 learn]# ll
total 0
---------- 1 root root 0 Jun 9 10:27 mymkdir
[root@test1 learn]#
添加要求权限方法二:
```bash
[root@test1 learn]# chmod 755 mymkdir
[root@test1 learn]# ll
total 0
-rwxr-xr-x 1 root root 0 Jun 9 10:27 mymkdir
[root@test1 learn]#
设置文件的归属chown
- 格式
- chown 属主 文件
- chown :属组 文件
- chown 属主:属组 文件
示例:将mymkdir文件的属主更改为daemon、属组更改为wheel
[root@test1 learn]# chown --help
Usage: chown [OPTION]... [OWNER][:[GROUP]] FILE...
or: chown [OPTION]... --reference=RFILE FILE...
Change the owner and/or group of each FILE to OWNER and/or GROUP.
With --reference, change the owner and group of each FILE to those of RFILE.
-c, --changes like verbose but report only when a change is made
--dereference affect the referent of each symbolic link (this is
the default), rather than the symbolic link itself
-h, --no-dereference affect each symbolic link instead of any referenced
file (useful only on systems that can change the
ownership of a symlink)
--from=CURRENT_OWNER:CURRENT_GROUP
change the owner and/or group of each file only if
its current owner and/or group match those specified
here. Either may be omitted, in which case a match
is not required for the omitted attribute.
--no-preserve-root do not treat `/' specially (the default)
--preserve-root fail to operate recursively on `/'
-f, --silent, --quiet suppress most error messages
--reference=RFILE use RFILE's owner and group rather than
specifying OWNER:GROUP values
-R, --recursive operate on files and directories recursively
-v, --verbose output a diagnostic for every file processed
The following options modify how a hierarchy is traversed when the -R
option is also specified. If more than one is specified, only the final
one takes effect.
-H if a command line argument is a symbolic link
to a directory, traverse it
-L traverse every symbolic link to a directory
encountered
-P do not traverse any symbolic links (default)
--help display this help and exit
--version output version information and exit
Owner is unchanged if missing. Group is unchanged if missing, but changed
to login group if implied by a `:' following a symbolic OWNER.
OWNER and GROUP may be numeric as well as symbolic.
Examples:
chown root /u Change the owner of /u to "root".
chown root:staff /u Likewise, but also change its group to "staff".
chown -hR root /u Change the owner of /u and subfiles to "root".
Report chown bugs to [email protected]
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'chown invocation'
[root@test1 learn]#
omit [o·mit || ə'mɪt]
v. 省略, 遗漏, 疏忽
traverse [trav·erse || 'trævə(r)s]
v. 横过, 经过, 穿过; 横越, 旋转, 横断
adj. 横断的, 横的
示例:
查看
[root@test1 learn]# id daemon
uid=2(daemon) gid=2(daemon) groups=2(daemon),1(bin),4(adm),7(lp)
[root@test1 learn]#
[root@test1 learn]# grep 'wheel' /etc/group
wheel:x:10:
[root@test1 learn]# grep "wheel" /etc/group
wheel:x:10:
[root@test1 learn]#
更改
[root@test1 learn]# chown deamon:wheel mymkdir
chown: invalid user: `deamon:wheel' (拼写错误)
[root@test1 learn]# chown daemon:wheel mymkdir
[root@test1 learn]# ll
total 0
-rwxr-xr-x 1 daemon wheel 0 Jun 9 10:27 mymkdir
[root@test1 learn]#
另一种更改组的方法:
[root@test1 learn]# chgrp root mymkdir
[root@test1 learn]#
[root@test1 learn]# ll
total 0
-rwxr-xr-x 1 daemon root 0 Jun 9 10:27 mymkdir
[root@test1 learn]#