Linux under chmod 777 and 0777 permission settings

Source: Internet
Author: User
Tags chmod mkdir

1. Use mkdir ("test", 777) to correct the error when programming

Try this:

mkdir ("Test", 0777);

Written as mkdir ("test", 777) may not be able to execute. But vaguely remember, used to be 777 without errors, specifically forgotten, anyway, according to the specification is absolutely right.

2, umask command to use

In addition to assuming that your program directory is under/root/abc/, if your program executes to create a directory under/var/www, it is possible that you always create a 0777 directory always create a 0755 directory, then you can try to use the umask (0) command.

Umask is only valid for the current directory, and the default Umask value is 0022, so you cannot create a 0777 directory directly from another location.

But 0777-0022=0755.

3. How to create a folder for a user group

/etc/passwd and/etc/group find UID and GID


We can use Chown directly to change the file owner.

Chown Root:newuser/var/ugroup

Modify Permissions

chmod 740/var/ugroup/*

4, see the creation of directory permissions after the command:

Navigate to the user group directory and execute:


will display a similar:


Such a result (0775).

chmod----Change the access mode of one or more files (mode)
chmod [options] mode files
Only file owners or privileged users can use this feature to change file access mode. Mode can be a digital form or expressed in the form of who opcode permission. Who is optional, by default is a (all users). Only one opcode (opcode) can be selected. Multiple mode can be specified, separated by commas.

Only the information of the changed file is exported
The user who does not notify the file when chmod cannot change the file mode
Output help information.
Recursively traverse subdirectories and modify all files and subdirectories in the directory
To set permissions by referencing the permissions of filename
Output information for each file, regardless of whether the modification was successful
Output version information.
All Users (default)
Increase permissions
Delete permissions
Reassign permissions

Set the ID number of a user (or group)
Set sticky bit (sticky bit) to prevent files or directories from being deleted by non-owner
User's current permissions
Current permissions for Group
Current permissions for other users

As a choice, most of us use the form of three-digit octal numbers to represent permissions, the first specifies the owner's permissions, the second specifies the group permissions, the third specifies the permissions of the other user, and each digit determines the permissions by 4 (read), 2 (write), 1 (execute) three numeric values. If 6 (4+2) Representative has the right to read and write, 7 (4+2+1) has read, writes and executes the permission.


can also set the fourth bit, which precedes the three-bit permission sequence, and the fourth digit value is 4,2,1, which means the following:
4, set the user ID at execution time to authorize the file-based process, rather than to the user who created the process.
2, set the user group ID at execution time to authorize the process based on the group of files, rather than the user who created the process.
1, setting the sticky bit.

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: 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.