Chinaunix首页 | 论坛 | 博客
  • 博客访问: 589773
  • 博文数量: 207
  • 博客积分: 10128
  • 博客等级: 上将
  • 技术积分: 2440
  • 用 户 组: 普通用户
  • 注册时间: 2004-10-10 21:40
文章分类

全部博文(207)

文章存档

2009年(200)

2008年(7)

我的朋友

分类: LINUX

2009-04-21 10:36:23

Unix and Linux operating systems assign access rights to files and directories using one of three types of access (read, write and execute) assigned to each of three groups (owner, group and other users).

If you list details of a file's attributes using the ls command with the -l switch (for example ls -l filename), it would return information that would look something like -rwe-rw-r-- which equates to read, write and execute privileges for the owner, read and write privileges for the group and only read access for all other users.

Each of the types of access rights has an associated numeric value listed below:

  • read = 4
  • write = 2
  • execute = 1

The values for the access rights for each of the groups is added together to obtain a value between 0 and 7 which can be used to assign or modify permissions using the chmod (change mode) command.

In the example above, the access rights for the file in question could be assigned by entering chmod 764 filename. The number 764 is derived from:

  • rwe = 4 (read) + 2 (write) + 1 (execute) = 7
  • rw = 4 (read) + 2 (write) = 6
  • r = 4 (read) = 4
You can use the chmod command to assign access rights to files and directories. Keep in mind that Unix and Linux commands and object names are case sensitive. You must use "chmod" and not CHMod or any other combination of upper and lower case letters.

Below are some other examples of how to use the chmod command:

  • full access for everybody:
    chmod 777 filename
  • full access for owner and group privileges but other users can only read and execute:
    chmod 775 filename
  • full access for owner, but restricting group and other user privileges to only read and execute for files in the directory:
    chmod 755 dirname
  • full access for the owner with no access rights or privileges for anyone else:
    chmod 700 filename
  • no access to files in directory for group or other users and owner restricted to read and execute privileges to prevent the accidental deletion or modification of files in the directory:
    chmod 500 dirname
  • allowing the owner and group read and write access to a file, allowing others in the group to edit or delete the file as well as the owner, but with no access for other users:
    chmod 660 filename
阅读(760) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~