首页 > 系统服务 > 详细

linux常用命令2 chmod、chown

时间:2015-07-19 23:48:34      阅读:287      评论:0      收藏:0      [点我收藏+]

chmod命令

[root@wangchao ~]# ls -l

total 104

drwxr-xr-x. 3 root root  4096 Jul  2 22:34 222

 

看此处drwxr-xr-xr=4,w=2,x=1,因此rwx=4+2+1=7,r-x=4+1=5, r-x=4+1=5,因此该文件权限可表示为755

[root@wangchao ~]# chmod 744 222          //222目录权限改为744,744权限=rwxr--r--

[root@wangchao ~]# ls -ld 222                 //查看权限已更改 

drwxr--r--. 3 root root 4096 Jul  2 22:34 222

 

[root@wangchao ~]# chmod u=rwx,g=r--,o=r-- 222

//用该方法与chmod 744 222达到一样的效果,uuser主,ggroup组,oother其他

[root@wangchao ~]# ls -ld 222

drwxr--r--. 3 root root 4096 Jul  2 22:34 222

 

[root@wangchao ~]# chmod u-x 222                  //userx权限

[root@wangchao ~]# ls -ld 222

drw-r--r--. 3 root root 4096 Jul  2 22:34 222

 

[root@wangchao ~]# chmod u+x,g+w,o-r 222          //ux权限,gw权限,or权限

[root@wangchao ~]# ls -ld 222

drwxrw----. 3 root root 4096 Jul  2 22:34 222

 

[root@wangchao ~]# chmod a+r 222                  //所有都加r权限,all+r

[root@wangchao ~]# ls -ld 222

drwxrw-r--. 3 root root 4096 Jul  2 22:34 222

 

 

 

 

[root@wangchao ~]# mkdir 222/234

[root@wangchao ~]# tree 222

222

├── 111

   └── 123.txt

└── 234

 

2 directories, 1 file

[root@wangchao ~]# ls -l 222

total 8

drwxr-xr-x. 2 root root 4096 Jul  2 22:25 111

drwxr-xr-x. 2 root root 4096 Jul  2 23:15 234

[root@wangchao ~]# ls -l 222/111/

total 48

-rw-r--r--. 1 root root 48308 Jul  2 22:25 123.txt

 

[root@wangchao ~]# chmod -R 700 222                    //使222文件只有主有权限

[root@wangchao ~]# ls -l 222

total 8

drwx------. 2 root root 4096 Jul  2 22:25 111                //文件所有权限改为700

drwx------. 2 root root 4096 Jul  2 23:15 234

 

[root@wangchao ~]# umask                      //默认目录文件属性0022

0022

[root@wangchao ~]# mkdir 1112                  //创建目录默认权限为777-022

[root@wangchao ~]# ls -ld 1112/

drwxr-xr-x. 2 root root 4096 Jul  3 06:06 1112/

 

[root@wangchao ~]# touch 12.txt      //创建文件默认权限为666-022,(文件不需要X权限)

[root@wangchao ~]# ls -ld 12.txt

-rw-r--r--. 1 root root 0 Jul  3 06:07 12.txt

 

[root@wangchao ~]# umask 011              //更改umask

[root@wangchao ~]# umask

0011

[root@wangchao ~]# umask 022

 

 

 

 

chown命令

[root@wangchao ~]# ls -l

-rw-r--r--. 1 root root 48308 Jul  2 23:02 1.txt

[root@wangchao ~]# chown wangchao 1.txt

chown: invalid user: `wangchao‘                        //无该用户

[root@wangchao ~]# useradd wangchao                 //创建用户wangchao          

[root@wangchao ~]# groupadd user1                   //创建组user1

[root@wangchao ~]# chown  :user1 1.txt                //改文件组为user1

[root@wangchao ~]# ls -l 1.txt

-rw-r--r--. 1 root user1 48308 Jul  2 23:02 1.txt

[root@wangchao ~]# chown root:root 1.txt                 //主、组改回rootroot

[root@wangchao ~]# ls -l 1.txt

-rw-r--r--. 1 root root 48308 Jul  2 23:02 1.txt

 

[root@wangchao ~]# chown -R wangchao:user1 1112/            //级联更改子目录主、组

 

 

[root@wangchao ~]# !ls                            //执行上一条执行过ls的命令

ls -l 1.txt

-rw-r--r--. 1 root root 48308 Jul  2 23:02 1.txt

[root@wangchao ~]# history                        //查看使用的历史命令

  654  ls -l 1.txt

  655  history

[root@wangchao ~]# !654                         //执行历史命令中第654条命令

ls -l 1.txt

-rw-r--r--. 1 root root 48308 Jul  2 23:02 1.txt

 

 

 

 

本文出自 “Linux学习笔记” 博客,请务必保留此出处http://9656134.blog.51cto.com/9646134/1676164

linux常用命令2 chmod、chown

原文:http://9656134.blog.51cto.com/9646134/1676164

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!