Home>Article>Operation and Maintenance> Is there an access function in linux?

Is there an access function in linux?

WBOY
WBOY Original
2022-05-17 17:25:59 3357browse

There is an access function in Linux; this function is used to check the user's permissions on a file. If the specified access method is valid, the function returns 0, otherwise the function returns "-1", and the syntax is " int access(const char* pathname, int mode);".

Is there an access function in linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

Is there an access function in linux?

Is there an access function in linux

access function header file: unistd.h Function: Determine the file or folder access rights. That is, check the access mode of a certain file, such as read-only mode, write-only mode, etc. If the specified access method is valid, the function returns 0, otherwise the function returns -1.

The syntax is:

#include int access(const char* pathname, int mode);

Parameter introduction:

pathname is the path name of the file file name

mode: specifies the role of access, take The values are as follows

  • F_OK value is 0, determine whether the file exists

  • ##X_OK value is 1, determine whether the file has executable permission

  • W_OK value is 2, determine whether the file has write permission

  • R_OK value is 4, determine whether the file has read permission

Note: The last three can be used together with "|", such as W_OK|R_OK

For example:

access("test",06); access("test",F_OK);

are used to check the actual user pair respectively. Whether the test file has read and write permissions and whether the test file exists.

Recommended learning:

Linux video tutorial

The above is the detailed content of Is there an access function in linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is the h file in linux Next article:What is the h file in linux