chmod命令 chown命令 id命令 install命令

2015-07-19 13:10:00
admin
原创 2352
摘要:chmod命令 chown命令 id命令 install命令

一、chmod

chmod [options] mode files

文件属主或特权用户使用该命令来改变文件权限。mode可以是数字形式或者who opcode permission形式表示,who是可选的,默认a所有用户,只能选择一个opcode操作码。可指定多个mode,以逗号分开:

-R, --recursive:change files and directories recursively;

who:u用户、g组、o其它、a所有用户(默认);
opcode:+增加权限、-删除权限、=重新分配权限;
permission:r读、w写、x执行、用户或组s属性、t设置粘着位sticky bit,防止文件或目录被非属主删除;


添加文件可执行权限:

chmod -x myfile
ls -l myfile
-rw-r--r--. 1 root root 0 6月  27 17:11 myfile
chmod +x myfile
ls -l myfile
-rwxr-xr-x. 1 root root 0 6月  27 17:11 myfile


设置文件所有权限:

ls -l myfile
-rw-r--r--. 1 root root 0 7月  25 09:54 myfile
chmod 7777 myfile
ls -l myfile
-rwsrwsrwt. 1 root root 0 7月  25 09:54 myfile


1、设置文件s属性,设置后程序会以文件的用户或组权限执行程序(geteuid,getegid);

2、设置目录g+s属性,目录下任何用户创建文件的组都是目录的组;

3、chmod u+s g+s +s,n1n2n3n4,n1=x1x2x3,x1表示用户s属性,x2表示组s属性,x3表示t粘着位;

chmod +s /usr/bin/vim
ls -l /usr/bin/vim
-rwsr-sr-x. 1 root root 1967072 4月   5 2012 /usr/bin/vim

chmod -x /usr/bin/vim
ls -l /usr/bin/vim
-rwSr-Sr--. 1 root root 1967072 4月   5 2012 /usr/bin/vim


设置t属性,t属性只对目录有效,目录中由目录所有者创建的文件只能被目录所有者删除:

chmod +t tmp
ls -al tmp
drwxr-xr-t.  2 root root 4096 10月 30 2013
drwxr-xr-x. 12 root root 4096 7月  19 16:09


二、chown

chown [OPTION]... [OWNER][:[GROUP]] FILE...


显示文件所属的用户和组:ls -l myfile,-rw-rw-r--. 1 test001 test001 0 7月  19 17:19 myfile

改变文件所属用户:chown test002 myfile

改变文件所属组:chown :test002 myfile


三、id命令

print  user  and  group  information  for the specified USERNAME:

id root

uid=0(root) gid=0(root) 组=0(root)


四、install命令

makefile基本使用install命令安装程序,因为install命令相比cp:

1、cp清空文件再写文件,cp操作文件inode不会变,install删除文件再创建文件,相比cp会更安全;

2、install命令可以使用-g、-o、-m同时设置文件组、所有者、权限;

3、不指定-m参数时,权限默认rwxr-xr-x;

4、-p参数可以使目标文件保留源文件的访问和修改时间;

发表评论
评论通过审核之后才会显示。