What are the permissions of a file or directory in Linux
three file permissions
- text read file content (r);
- write data to file(w);
- Execute file(x) as a command.
Three permissions for directories
- read the name of the file contained in the directory (r);
- write information to the directory (add and delete links to index points, w);
- Search a directory (can use the directory name as a pathname to access the files and subdirectories it contains, x).
chmod command parsing
chmod uses 3 numbers to express the user (the owner of the file or directory, usually the creator of the file), the user group (when a user creates a file, the group of the file is the group of the user) and permissions of other users, such as:
**chmod 777 /home/user ** Note: Only set the permissions of the /home/user directory to rwxrwxrwx
**chmod -R 777 /home/user ** Note: It means to set the permissions of the entire /home/user directory and its files and subdirectories to rwxrwxrwx
details as follows:
- Read----represented by the number 4;
- Write----represented by the number 2;
- Execute----represented by the number 1.
According to the rules, if you want to set the permissions of the /test directory to:
- Readable and writable to the user: 4 (read) + 2 (write) = 6;
- Readable and executable for user group: 4 (read) + 1 (execute) = 5;
- Read only to other users: 4 (read);
So you can use the command: chmod 654 /test
Several common permission examples
- -rw------- (600) Only the owner has read and write permissions
- -rw-r--r-- (644) Read and write permissions only for owner, group and others only read permissions
- -rwx------ (700) Only the owner has read, write, and execute permissions
- -rwxr-xr-x (755) Only owner has read, write, execute permissions, group and others only have read and execute permissions
- -rwx--x--x (711) Only owner has read, write, execute permissions, group and others have execute permissions only
- -rw-rw-rw- (666) Everyone has read and write permissions
- -rwxrwxrwx (777) Everyone has read, write and execute permissions