CHMOD and fchmod functions/chown, fchown, and lchown Functions

Source: Internet
Author: User

These two functions allow us to change the access permissions of existing files:

# Include <sys/STAT. h> int chmod (const char * pathname, mode_t mode); int fchmod (INT filedes, mode_t mode); two function return values: 0 if successful, and-1 if an error occurs

 

The chmod function operates on the specified file, while the fchmod function operates on the opened file.

To change the permission bit of a file, the valid user ID of the process must be equal to the owner ID of the file, or the process must have the superuser permission.

A bitwise OR operation of constants in the mode parameter.

Mode Description
S_isuid
S_isgid
S_isvtx
Set User ID during execution
Set Group ID during execution
Save the body (sticky position)
S_irwxu
S_irusr
S_iwusr
S_ixusr
User (owner) read, write, and execute
User (owner) read
User (owner) Write
User (owner) Execution
S_irwxg
S_irgrp
S_iwgrp
S_ixgrp
Group read, write, and execution
Group read
Group Write
Group execution
S_irwxo
S_iroth
S_iwoth
S_ixoth
Other reads, writes, and executions
Other reads
Others
Other executions

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The chown function can be used to change the user ID and group ID of a file:

# Include <unistd. h> int chown (const char * pathname, uid_t owner, gid_t group); int fchown (INT filedes, uid_t owner, gid_t group); int lchown (const char * pathname, uid_t owner, gid_t group); return values of the three functions: 0 if successful, and-1 if an error occurs.

 

CHMOD and fchmod functions/chown, fchown, and lchown Functions

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.