chown命令应用和chmod命令应用
admin
2024-02-25 01:02:39
0

记录: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 isthe 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 theownership of a symlink)--from=CURRENT_OWNER:CURRENT_GROUPchange the owner and/or group of each file only ifits current owner and/or group match those specifiedhere.  Either may be omitted, in which case a matchis 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 thanspecifying OWNER:GROUP values-R, --recursive        operate on files and directories recursivelyThe 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 linkto a directory, traverse it-L                     traverse every symbolic link to a directoryencountered-P                     do not traverse any symbolic links (default)--help     display this help and exit--version  output version information and exitOwner 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: 
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 exitEach MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'.GNU coreutils online help: 
For complete documentation, run: info coreutils 'chmod invocation'

以上,感谢。

2022年11月28日

相关内容

热门资讯

贝特利IPO,核心业务成长性、... 中国网财经2月2日讯 近期,苏州市贝特利高分子材料股份有限公司(简称“贝特利”)回复二轮审核问询函,...
A股三大指数均跌超1%!黄金股... 2月2日早盘,A股低开震荡,截至午间收盘,沪指跌1.32%,深成指跌1.41%,创业板指跌1.18%...
和讯投顾周大勇:慢就是快,切忌... 许多投资者或许有过类似经历:明明拥有一套稳定盈利的方法,却总是忍不住追逐热点、更换模式,最终越做越亏...
穿499元的鞋,敲千亿市值的钟... 文|无相财经 白色卫衣、卷边牛仔裤、券后499元的国潮鞋,上市敲锣时轻轻一点,波澜不惊……这大概是...
小红书爆款笔记秘诀!4步轻松拿... 运营小红书的宝子们,是不是总卡在内容环节?明明做好了赛道定位、找好了对标,却始终做不出戳中用户的爆款...
为何说石家庄眼科是近视手术的优... 近视手术价格考量因素 在考虑近视手术时,很多人会关注价格是否昂贵。其实,手术价格受多种因素影响,如手...
腾讯回应元宝“崩了”,多只算力... AI厂商激战春节“营销档”,带来算力需求增长。 2月2日凌晨,第一财经记者在腾讯元宝看到,从领现金红...
1月4家IPO审核终止,远低去... 财联社2月2日讯(记者 赵昕睿)三大交易所官网显示,今年1月共计4家IPO终止,较去年同期的29家大...
惠东臻品走进广州商圈,联动展销... 1月30日,由广东省“百千万工程”纵向帮扶工作队联合多家省属企业主办的“山海惠东·品味时尚”促消费活...
中长期资金入市有望推动银行板块... 2月2日,三大股指早盘持续走低,其中银行板块逆势拉升。截至上午10:30,银行ETF南方(15935...
移动互联与AI时代的律所管理,... 来源:市场资讯 (来源:第一法商CHANNEL) 管理,是生产力。 思想前进一小步,事业前进一大步。...
刚刚,崩了!大面积跌停!这一板... 【导读】有色金属板块继续暴跌,个股开盘大面积跌停;石油石化板块不振,三大运营商集体走低;白酒股再度冲...
以后的黄金会是以前的房子吗? 有人的地方就有江湖,有金钱的地方就有喜忧。 最近贵金属的价格像过山车一样跌宕起伏,相信关注的朋友都深...
东契奇30+15布伦森12+1... 【搜狐体育战报】北京时间2月2日NBA常规赛,主场作战的尼克斯以112-100击败湖人,尼克斯取得6...
商业航天产业链共链行动大会在上... 2026年1月29日,以“链聚产业合力 共建航天强国”为主题的商业航天器及应用产业链共链行动大会在上...
中山公用事业集团股份有限公司 ... 来源:证券日报 证券代码:000685 证券简称:中山公用 公告编号:2026-006 本公司及董...
玖亓周评 | 一日暴跌创下40... 黄金成了新的修罗场。 1月30日,黄金价格经历了踩踏式的暴跌,并且是过山车式的暴跌。现货黄金价格在势...
华为云发布“行业AI梦工厂”智... 科技日报 科技日报记者 崔爽 AI正向产业落地深水区迈进。2月1日举行的医疗人工智能协同创新论坛暨医...
港股IPO热潮背后:中资券商的... 来源:梧桐树下v 继2025年IPO募资额问鼎全球榜首之后,港股市场在2026年延续了这份灼热势头—...