Linux chmod settings directory and file different permissions

Source: Internet
Author: User
Tags chmod readable file permissions


Law: chmod [who] [+ |-| =] [mode] filename

The meanings of the options in the command are

U represents "User", which is the owner of a file or directory.
G means "same group of users", that is, all users who have the same group ID as the owner of the file.
O Represents "other (others) users".
A represents "All users". It is the system default value.
The action symbol can be:
+ Add a permission.
-Cancels a permission.
= gives the given permission and cancels all other permissions, if any.
The permissions represented by mode set can be any combination of the following letters:
R readable.
W can be written.
X executable.
x attributes are appended only if the target file is executable for some users or if the destination file is a directory.
s the owner or group ID of the process to the file owner of the file when the file is executed. Mode "U+s" sets the user ID bit of the file, and "G+s" sets the group ID bit.
T saves the text of the program to the switching device.
You have the same permissions as the owner of the file.
G has the same permissions as the user of the same group as the file owner.
o have the same permissions as other users.


Use command chmod to change file permissions. There are two kinds of

First Kind

chmod (Ugoa) (=-+) (rwx) file
U represents file Owner, G represents file genus, O represents other users in the system other than the owners and members of the group, a represents all users (u,g,o) sum
+ delegate increases the appropriate permissions,-the delegate reduces the appropriate permissions, = represents only the appropriate permissions
chmod g-w file will be able to complete the above document permissions to correct.

Second Kind

Correct with number, R for 4,w for 2,x 1
Add the number is the corresponding permission, as RWX is 7,RW is 6
The right method to correct the problem above is
chmod 775 file is fine.

The occasional command to use, record AH.

Find/path-type f-exec chmod 644 {};

Find/path-type d-exec chmod 755 {};

Example:


(1) Set the file file1.txt to be readable by all people:

chmod ugo+r File1.txt

(2) Set the file file1.txt to be readable by all people:

chmod a+r File1.txt
(3) To set the file File1.txt and File2.txt as the owner of the file, and to write to the same group as which it belongs, but other people are not writable:

chmod ug+w,o-w file1.txt File2.txt

(4) The ex1.py is set to be the only owner of the file who can perform:

chmod u+x ex1.py

(5) All files and subdirectories under the current directory are set to anyone can read:

Chmod-r A+r *

(6) Reclaim all user's execution rights to File1

chmod a-x File1

Use numbers to assign weights

4.1 First look at the file permission format

[Root@qs-wg-db2 scripts]# LL

Total 20

-rw-r--r--1 Oracle Oinstall 0 Feb 00:00 Alertlogbyday.log

-rwxr-xr-x 1 Oracle oinstall 430 FEB 01:10 alertlogbyday.sh

-rwxr-xr-x 1 Oracle Oinstall 7 Feb 05:00 Del_st_arch.log

-rwxr-xr-x 1 Oracle Oinstall 648 Feb 00:51 del_st_archive.sh

-rwxr-xr-x 1 Oracle Oinstall 9 Feb 05:00 Max_sn.log

Drwxr-xr-x 3 root root 4096 Feb 23:40 pymonitor

LL's result returns seven columns, respectively, to denote the following meanings:
First column [File properties]

second column [Number of files]

third column [owner]

Column four [owner Group]

Column five [size]

Section VI [Date of filing]

Seventh column [file name]


Example: Set the file file1.txt to be readable by all people:
  

1.chmod Ugo+r File1.txt
  
  

Set the file file1.txt to be readable by all people:
 

1. chmod a+r file1.txt
  
  

The file file1.txt and File2.txt are set to the owner of the file and are writable by the same group as which they belong, but others are not writable:
  

1.chmod ug+w,o-w file1.txt File2.txt
  
  

Set ex1.py as only the owner of the file can perform:
  

1.chmod u+x ex1.py
  
  

All files and subdirectories under the current directory are set to anyone can read:
  

1.chmod-r A+r *
  
  

In addition chmod can also use numbers to indicate permissions such as chmod 777 file
  

1. The syntax is: chmod ABC file
  
Each of these a,b,c is a number, representing the permissions of user, Group, and other respectively.
  
R=4,w=2,x=1
To rwx the property is 4+2+1=7;
To rw-the property is 4+2=6;
To r-x the property is 4+1=5.
  
Example:
  

1.chmod a=rwx File
  
And
  

1.chmod 777 File
  
Same effect
  

1.chmod ug=rwx,o=x File
  
And
  

1.chmod 771 File
  
Same effect
  
If you use chmod 4755 filename, you can make this program have root permissions

Related Article

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.