记录:350
场景:在CentOS 7.9操作系统上,使用chown变更目录和文件拥有者;使用chmod改变目录和文件的读写执行权限。
版本:
操作系统:CentOS 7.9
1.chown命令应用
(1)变更目录的拥有者
命令:chown -R dmysql:dmysql /home/apps/module/mysql
解析:chown,改变目录和文件的拥有者;-R,递归操作文件和目录,也就是目录下全部子目录和文件都改变;dmysql:dmysql,用户组和用户名;/home/apps/module/mysql,要改表用户拥有者的目录。
(2)变更目录的拥有者
命令:chown -Rv dmysql:dmysql /home/apps/module/mysql
解析:-v,打印变更的输出日志。
2.chmod命令应用
2.1文件权限解析
使用ll命令查看,目录和文件前面:drwxr-xr-x。这个字符串就是说明目录和文件权限。
(1)解析drwxr-xr-x
第1位表示文件类型,d是目录文件,l是链接文件,-是普通文件,p是管道。
第2到10位字符,表示权限。
(2)解析rwxr-xr-x
权限分为四种:读(r=4),写(w=2),执行(x=1),没权限(-)。
rwx,即1到3位字符,表示文件所有者的权限。
r-x,即4到6位字符,表示与文件所有者同属一个用户组的其他用户的权限。
r-x,即7到9位字符,表示其它用户组的权限。
(3)解析755和rwxr-xr-x
命令:chmod -R 755 /home/apps/module/mysql
解析:
7,是前3位rwx字符对应的数值之和,也就是4+2+1之和为7。
5,是4到6位r-x字符对应的数值之和,也就是4+0+1之和为5。
5,是7到9位r-x字符对应的数值之和,也就是4+0+1之和为5。
(4)赋权限两种方式
方式一:chmod -R 755 /home/apps/module/mysql
方式二:chmod -R +x /home/apps/module/mysql
解析:使用字母时,使用+号,加权限。
2.2chmod命令应用
(1)目录赋权
命令:chmod -R 755 /home/apps/module/mysql
解析:对目录赋权;-R,递归操作文件和目录,也就是目录下全部子目录和文件都会赋权。
(2)添加可执行权限
命令:chmod +x /home/apps/module/work
解析:给文件work添加可执行权限。
(3)目录赋权
命令:chmod -Rv 755 /home/apps/module/mysql
解析:对目录赋权;-R,递归操作文件和目录,也就是目录下全部子目录和文件都会赋权,-v,输出改变赋权日志信息。
3.命令帮助手册
(1)chown命令帮助文档
命令:chown --help
解析:查看chown支持的全部命令和选项,在实际工作中,查看这个手册应该是必备之选。
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
-f, --silent, --quiet suppress most error messages
-v, --verbose output a diagnostic for every file processed
--dereference affect the referent of each symbolic link (this is
the default), rather than the symbolic link itself
-h, --no-dereference affect symbolic links 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 '/'
--reference=RFILE use RFILE's owner and group rather than
specifying OWNER:GROUP values
-R, --recursive operate on files and directories recursively
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".
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'chown invocation'
(2)chmod命令帮助文档
命令:chmod --help
解析:查看chmod支持的全部命令和选项,在实际工作中,查看这个手册应该是必备之选。
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.
With --reference, change the mode of each FILE to that of RFILE.
-c, --changes like verbose but report only when a change is made
-f, --silent, --quiet suppress most error messages
-v, --verbose output a diagnostic for every file processed
--no-preserve-root do not treat '/' specially (the default)
--preserve-root fail to operate recursively on '/'
--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]))+|[-+=][0-7]+'.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'chmod invocation'
以上,感谢。
2022年11月28日