1 chown简介 chown命令用于改变文件或目录的所有者和所属组(只有文件所有者或超级用户才可以使用该命令),可以向某用户授权,使该用户变成文件的所有者或者改变文件所属的组。 1.1 命令格式chown [option]... user[:group] file... 1.2 chown常用option
1.3 chown示例示例文本信息(每次示例后将恢复原来所有者和所属组,即root:root) root@LTY:/opt# ll test.txt-rw-r-----1 root root 0 Aug 13 10:07 test.txtroot@LTY:/opt# ll test1.txt-rw-r-----1 oracle oracle 0 Aug 13 10:07 test1.txt 1)把test.txt的所有者和所属组改为oracle root@LTY:/opt # chownoracle:oracle test.txtroot@LTY:/opt #ll test.txt-rw-rw--wx 1 oracleoracle 0 Aug 13 10:07 test.txt 2)把test.txt的所有者改为oracle,所属组保持不变 root@LTY:/opt # chownoracle: test.txtroot@LTY:/opt #ll test.txt-r-------- 1 oracleroot 0 Aug 13 10:17 test.txt 3)把test.txt的所属组改为oracle,所有者保持不变 root@LTY:/opt #chown :oracle test.txtroot@LTY:/opt #ll test.txt-r-------- 1 rootoracle 0 Aug 13 10:17 test.txt 4)使用--reference选项,将test1.txt的所有者和所属组改成与test.txt一样 root@LTY:/opt #chown --reference=test.txt test1.txtroot@LTY:/opt #ll test1.txt-r-------- 1 rootroot 0 Aug 13 10:17 test1.txt 2 chmod简介chmod命令用于改变Linux系统文件或目录的访问权限,只能是文件属主或特权用户才能使用该功能来改变文件存取模式。 2.1 命令格式chmod [option]... MODE[,MODE]... FILE... == 使用符号模式,例如chmod a+x file chmod [option]... OCTAL-MODE FILE... == 使用绝对模式,例如chmod 777 file 2.2 权限范围
说明:使用ll命令查看文件或目录权限时,例如“-rw-r-----”,第1位为文件类型(-:普通文件,d:目录文件,b:块设备文件,c:字符设备文件,l:符号链,p:管道特殊文件),第2~4位为拥有者权限,第5~7位为所组权限,第8~10位为其他用户权限。 2.3 chmod常用option
2.4 chmod示例示例文本信息(每次示例后将恢复原来的权限,即-rw-r-----) root@LTY:/opt# ll test.txt-rw-r-----1 root root 0 Aug 13 10:07 test.txt 1)增加test.txt所属组的写权限,增加其他用户的读权限和执行权限 root@LTY:/opt # chmodg+w,o+wx test.txtroot@LTY:/opt #ll test.txt-rw-rw--wx 1 rootroot 0 Aug 13 10:07 test.txt 2)删除test.txt拥有者的写权限,删除所属组的读权限 root@LTY:/opt # chmodu-w,g-r test.txtroot@LTY:/opt #ll test.txt-r-------- 1 rootroot 0 Aug 13 10:17 test.txt 3)删除test.txt拥有者的写权限,删除所属组的读权限,使用数字修改 root@LTY:/opt # chmod400 test.txtroot@LTY:/opt # lltest.txt-r-------- 1 rootroot 0 Aug 13 10:28 test.txt 3 chgrp简介chgrp命令用于改变文件或目录所属组(只有文件所有者或超级用户才可以使用该命令),可以理解为“change group”的缩写。 3.1 命令格式chgrp [option]... [group] file... 3.2 chgrp常用option
3.3 chgrp示例示例文本信息(每次示例后将恢复原来所有者和所属组,即root:root) root@LTY:/opt# ll test.txt-rw-r-----1 root root 0 Aug 13 10:07 test.txt 1)把test.txt的所属组改为oracle root@LTY:/opt # chgrporacle test.txtroot@LTY:/opt #ll test.txt-rw-rw--wx 1 rootoracle 0 Aug 13 10:07 test.txt 推荐阅读: 【linux从放弃到入门】linux grep命令 【linux从放弃到入门】col、tr、join命令 【linux从放弃到入门】Linux sort命令 【linux从放弃到入门】linux find命令 看完本文有收获?请分享给更多的人 在技术成长的路上,让我们一起进步吧 ![]() ---------------------------------------------------------------------------------------------------------------------- 我们尊重原创,也注重分享,文章来源于微信公众号:码农之屋,建议关注公众号查看原文。如若侵权请联系qter@qter.org。 ---------------------------------------------------------------------------------------------------------------------- |