• chown命令应用和chmod命令应用


    记录: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支持的全部命令和选项,在实际工作中,查看这个手册应该是必备之选。

    1. Usage: chown [OPTION]... [OWNER][:[GROUP]] FILE...
    2. or: chown [OPTION]... --reference=RFILE FILE...
    3. Change the owner and/or group of each FILE to OWNER and/or GROUP.
    4. With --reference, change the owner and group of each FILE to those of RFILE.
    5. -c, --changes like verbose but report only when a change is made
    6. -f, --silent, --quiet suppress most error messages
    7. -v, --verbose output a diagnostic for every file processed
    8. --dereference affect the referent of each symbolic link (this is
    9. the default), rather than the symbolic link itself
    10. -h, --no-dereference affect symbolic links instead of any referenced file
    11. (useful only on systems that can change the
    12. ownership of a symlink)
    13. --from=CURRENT_OWNER:CURRENT_GROUP
    14. change the owner and/or group of each file only if
    15. its current owner and/or group match those specified
    16. here. Either may be omitted, in which case a match
    17. is not required for the omitted attribute
    18. --no-preserve-root do not treat '/' specially (the default)
    19. --preserve-root fail to operate recursively on '/'
    20. --reference=RFILE use RFILE's owner and group rather than
    21. specifying OWNER:GROUP values
    22. -R, --recursive operate on files and directories recursively
    23. The following options modify how a hierarchy is traversed when the -R
    24. option is also specified. If more than one is specified, only the final
    25. one takes effect.
    26. -H if a command line argument is a symbolic link
    27. to a directory, traverse it
    28. -L traverse every symbolic link to a directory
    29. encountered
    30. -P do not traverse any symbolic links (default)
    31. --help display this help and exit
    32. --version output version information and exit
    33. Owner is unchanged if missing. Group is unchanged if missing, but changed
    34. to login group if implied by a ':' following a symbolic OWNER.
    35. OWNER and GROUP may be numeric as well as symbolic.
    36. Examples:
    37. chown root /u Change the owner of /u to "root".
    38. chown root:staff /u Likewise, but also change its group to "staff".
    39. chown -hR root /u Change the owner of /u and subfiles to "root".
    40. GNU coreutils online help:
    41. For complete documentation, run: info coreutils 'chown invocation'

    (2)chmod命令帮助文档

    命令:chmod --help

    解析:查看chmod支持的全部命令和选项,在实际工作中,查看这个手册应该是必备之选。

    1. Usage: chmod [OPTION]... MODE[,MODE]... FILE...
    2. or: chmod [OPTION]... OCTAL-MODE FILE...
    3. or: chmod [OPTION]... --reference=RFILE FILE...
    4. Change the mode of each FILE to MODE.
    5. With --reference, change the mode of each FILE to that of RFILE.
    6. -c, --changes like verbose but report only when a change is made
    7. -f, --silent, --quiet suppress most error messages
    8. -v, --verbose output a diagnostic for every file processed
    9. --no-preserve-root do not treat '/' specially (the default)
    10. --preserve-root fail to operate recursively on '/'
    11. --reference=RFILE use RFILE's mode instead of MODE values
    12. -R, --recursive change files and directories recursively
    13. --help display this help and exit
    14. --version output version information and exit
    15. Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'.
    16. GNU coreutils online help:
    17. For complete documentation, run: info coreutils 'chmod invocation'

    以上,感谢。

    2022年11月28日

  • 相关阅读:
    小程序传值对象数值到另一个页面大小限制
    python之opencv人脸识别快速体验
    万字逐行解析与实现Transformer,并进行德译英实战(三)
    CentOS 7 mysql 安装以及常用语句(select、update、alter、rename、drop等)速查
    国密gmtls协议-双证书体系的服务端和客户端通信代码
    ES的索引结构与算法解析
    nginx(六十一)proxy模块(二)修改发往上游的请求
    Java关键字super解释
    爱创科技携手洽洽食品,探索渠道数字化最优解!
    用Abp实现双因素认证(Two-Factor Authentication, 2FA)登录(一):认证模块
  • 原文地址:https://blog.csdn.net/zhangbeizhen18/article/details/128086182