File permissions for Linux operating systems

Source: Internet
Author: User

Linux is inherited from Unix, and has been designed as a multi-user system. Let's illustrate it with actual examples.

~ /Test $ ls-l

-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B

The displayed information is represented by columns: file attributes, number of links (inode), owner, and group) file Size, latest modification date, and file (directory) Name.

1. File Attributes

A file or directory has 10 basic attributes, with 1st representing the type. The last nine attributes are divided into three groups, indicating the execution attributes of owner, group, and others respectively.

File Type: [d] Directory; [-] file; [l] link file ;...
Execution attribute: [r] readable; [w] writable; [x] executable.

-Rw-r -- 1 Yuanyuan yu1_0 a.txt

Indicates that the file owner can read/write (rw), user group (group), and other users (other) read-only (r ). You can also use numbers to represent r = 4, w = 2, x = 1, for example, rw-r -- = 644.

~ /Test $ ls-l

-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B

~ /Test $ chmod 664./a.txt

~ /Test $ ls-l

-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B

Of course, we can also use more intuitive parameters.

~ /Test $ chmod a + w a.txt # Set all to writable

~ /Test $ ls-l

-Rw-1 yustmyu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B

~ /Test $ chmod ug = rw, o = r a.txt # The owner and group can read and write, and other read-only

~ /Test $ ls-l

-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B

~ /Test $ chmod u = rw, g-w a.txt # The owner can read and write the group.

~ /Test $ ls-l

-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B

Parameter description:

(1) u = owner; g = group; o = other; a = u + g + o
(2) [=] settings; [-] Remove; [+] add.

For a directory, r indicates the permission to read the directory structure, w indicates that you can create, delete, and move files and subdirectories in the directory, and x indicates that you can enter the directory.

~ /Test $ ls-l

-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B

~ /Test $ chmod a-x./B # Remove x

~ /Test $ ls-l

-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drw-r -- 2 Yuanyuan YuanYi 4096 B

~ /Test $ cd B # unable to enter this directory

-Bash: cd: B: Permission denied

~ /Test $ chmod a + x B # restore

~ /Test $ ls-l

-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B

~ /Test $ cd B # enter correctly

Chmod supports the-R parameter to recursively modify all files and subdirectories in the directory.

In addition to the above basic attributes, you can also use chattr and lsattr to set and display hidden attributes.

  • Four pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • 4
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.