Linux command Mkdir&chmod&chown

Source: Internet
Author: User
Tags chmod readable

First, mkdir
- m, –mode= mode sets the permission mode (similar to chmod) instead of rwxrwxrwx minus Umask
Mkdir-m 755 Dir1
-p,–parents creates the upper-level directory of the target directory when needed, but is not treated as an error even if these directories already exist
Mkdir-p DIR1/SUB1/SUB2
-v,–verbose Displays information each time a new directory is created
-z,–context=ctx Set the SELinux security environment for each created directory to CTX

Second, chmod

Directive name  : chmod 
Use permissions  :  all user  
Usage  : chmod [-cfvr] [- -help] [--version] mode file... 
Description  : Linux/Unix  file invocation permissions are divided into three levels  :   File owners, groups, and others.  chmod  can be used to control how files are called by others.  
parameter  : 
-c :  If the file permission does change, the change action is displayed  
-f :  do not display an error message if the file permissions cannot be changed  
-v :  Show details of permission changes  
-r :  The same permission changes (that is, one-by-one)   for all files in the current directory and subdirectories;
--help :  Display the auxiliary description  
--version :   display version  
mode :  permission setting string, formatted as follows  : [ugoa ...] [[+-=][RWXX] ...] [,...], where  
u  indicates that the owner of the file,g  that the owner of the file belongs to the same group (group),o  Other people,a  said that all three were.  
+  indicates that the privilege is increased,-  represents a cancellation permission, and =  represents a unique set of permissions.  
r  means that a readable,w  indicates that a writable,x  indicates that the executable,x  represents only if the file is a subdirectory or the file has been set to be executable.  

Example 1: Set the file file1.txt to be read by all people:
chmod ugo+r File1.txt
Set the file file1.txt to be readable by everyone:
chmod a+r File1.txt
The file file1.txt and File2.txt are set as the owner of the file, and the same group as the person to which they belong can be written, but others other than the other are not writable:
chmod ug+w,o-w file1.txt File2.txt
Set ex1.py to only the owner of the file can perform:
chmod u+x ex1.py
Set all files and subdirectories in the current directory to be readable by anyone:
Chmod-r A+r *
In addition chmod can also use numbers to represent permissions such as chmod 777 file
The syntax is: chmod ABC file
Each of the a,b,c is a number that represents the permissions of the user, Group, and other respectively.
R=4,w=2,x=1
To rwx the attribute then 4+2+1=7;
To rw-the attribute then 4+2=6;
To r-x the property, 4+1=7.
Example 2:
chmod a=rwx File
And
chmod 777 File
Same effect
chmod ug=rwx,o=x File
And
chmod 771 File
Same effect
Using chmod 4755 filename allows this program to have root privileges.

Example 3:

Files that run the. sh File type:
Test with the file command to see what type of
File xxxx.sh
If it is bourne-again shell script can be sh xxxx.sh or chmod +x xxxx.sh again./xxx.sh
General. Sh Direct add x (Executable property) chmod +x xxx.sh and then./xxx.sh.
chmod +x test.sh
Default to U and G Add executable permission

Third, Chown

Directive Name: Chown
Usage rights: Root

How to use: chmod [-CFHVR] [--help] [--version] user[] File ...

Description: Linux/unix is a multi-person and multi-work system, with all files owned by the owner. The chown can be used to change the owner of the file. Generally speaking, this instruction is only used by the system administrator (root), the general user does not have the authority to change the other person's file owner, and does not have the authority to change the owner of their own files to other persons. Only the system administrator (root) has this permission.

Put the meter:

User: New file owner's user idgroup: The user group of the new file owner (group)-C: If the file owner has changed, the change action is not displayed-F: If the file owner cannot be changed, do not display the error message-H: Only the link is changed More, not the one that link really points to.-V: Shows the details of the owner change-r: the same owner change (that is, one-by-one change) for all files in the current directory and subdirectories--help: Display Auxiliary description--version: Display version

Example:
Set the owner of the archive file1.txt to the Users group user jessie:
Chown Jessie:users File1.txt

The owner of all files and subdirectories in the current directory is set to user Lamport of the Users group:
Chmod-r Lamport:users *
-RW-------(600)--only the master has read and write permission.
-rw-r--r--(644)--only the master has read and write permission, and the group user and other users have Read permission only.
-RWX------(700)--only the owner has read, write, and execute permissions.
-rwxr-xr-x (755)-The master has read, write, execute permission, but the group user and other users only read, execute permissions.
-rwx--x--x (711)-The master has read, write, execute permissions, but the group user and other users only execute permissions.
-rw-rw-rw-(666)--All users have file read and write permissions. This approach is undesirable.
-RWXRWXRWX (777)-All users have read, write, and execute permissions. More undesirable approach.
Here are two general settings for the directory:

DRWX------(700)-only the owner can read and write in the directory.
Drwxr-xr-x (755)-All users can read the directory, but only the owner can change the contents of the directory.

Linux command Mkdir&chmod&chown

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.