File permission meanings

2020-05-11 10:31发布

What do these file permissions mean? I am unable to understand them i tried looking at the 0-7 meanings but im unsure when they are together.

-r-------x
----rw---- 
-rwx--x--x

标签: linux unix
4条回答
混吃等死
2楼-- · 2020-05-11 10:51

From left to right, linux filesystem permissions are flags grouped in 3s

User (owner), Group, All

rwx------ = User can Read, Write, Execute

---rwx--- = Group can Read, Write, Execute

------rwx = All can Read Write, Execute

(I did not mention the flags for directory or setuid, on purpose)

etc

Next, you do not need to memorize numeric values for doing the setting

Use chmod with mnemonics

chmod a+r set the file such that All can Read

chmod g+r set the file such that Group can Read

chmod u+x set the file such that User can Execute

查看更多
冷血范
3楼-- · 2020-05-11 10:52

File permissions

Linux uses the same permissions scheme as Unix. Each file and directory on your system is assigned access rights for the owner of the file, the members of a group of related users, and everybody else. Rights can be assigned to read a file, to write a file, and to execute a file (i.e., run the file as a program).

To see the permission settings for a file, we can use the ls command as follows:

[me@linuxbox me]$ ls -l /bin/bash

-rwxr-xr-x 1 root root  316848 Feb 27  2000 /bin/bash

enter image description here

CHMOD

The chmod command is used to change the permissions of a file or directory. To use it, you specify the desired permission settings and the file or files that you wish to modify. There are two ways to specify the permissions, but I am only going to teach one way.

It is easy to think of the permission settings as a series of bits (which is how the computer thinks about them). Here's how it works:

rwx rwx rwx = 111 111 111
rw- rw- rw- = 110 110 110
rwx --- --- = 111 000 000

and so on...

rwx = 111 in binary = 7
rw- = 110 in binary = 6
r-x = 101 in binary = 5
r-- = 100 in binary = 4

Here is a table of numbers that covers all the common settings. The ones beginning with "7" are used with programs (since they enable execution) and the rest are for other kinds of files.

enter image description here

Directory permissions

The chmod command can also be used to control the access permissions for directories. In most ways, the permissions scheme for directories works the same way as they do with files. However, the execution permission is used in a different way. It provides control for access to file listing and other things. Here are some useful settings for directories:

enter image description here

查看更多
做自己的国王
4楼-- · 2020-05-11 10:53

Permissions as numbers are 3 octal numbers. 555, for example, when converted to 3 binary numbers is 101 101 101 which would correspond to r-x r-x r-x. The first set is owner, second set is group, third set is everyone else.

r = read

w = write

x = execute

If any of those are missing (-), then that set does not have those permissions.

查看更多
一纸荒年 Trace。
5楼-- · 2020-05-11 11:07

It's also

owner|group|all

-r-------x

owner can read, group can do nothing, others can excecute

----rw---- 

owner can do nothing, group can read and write, others can do nothing

-rwx--x--x

owner has full permission, group can execute, others can execute.

the first - is for special permissions such as sticky bit.

Here's a site that may help you.

查看更多
登录 后发表回答