“This is the 15th day of my participation in the Gengwen Challenge. For more details, see” Gengwen Challenge “.

In this article, we will learn permissions related operations.

root usersudo

The root user is a very special kind of user on UNIX-like systems. It has almost no restrictions, it can create, read, update and delete any file in the system.

Logging directly into the system as root is very dangerous, because you can break the system by doing something wrong.

We don’t usually log in directly as root, we use the sudo command only when we need it, which allows you to perform some operations as su (short for super User or root).

When you encounter a permission denied error, it is usually because you must be root at this point to operate. However, make sure again that you really want to do this. The sudo command usually requires you to enter the password of the current user.

View the operation permission of a filels -l

Run ls -l to view the file permission. The output is as follows:

shellLearn:~$ ls -l 
drwxr-xr-x   4 oracle dba       4096 May 20 11:47 oralog1
drwxr-x---  18 root   root      4096 May 20 13:51 root
Copy the code

You can see that there are similar drwxr-xr-x and drwxr-x– 10-letter strings appearing in the first column, what does that mean?

File permission Interpretation

First we need to understand the concept of user groups. A file belongs to user, and user belongs to a user group, the user group. Therefore, other users that are not in the user group naturally exist.

Each user or user group has three operations: read (r) write (w) execute (x). The following fields have permission meanings.

To drWXR-XR-X:

  • D indicates that the file type is directory
  • RWX: Bits 2-4 indicate the permissions that the owner of this file has. R is read, w is write, and x is execute
  • R-x: Bits 5-7 indicate the permissions for users in the same group as the owner of the file, only read and execute.
  • R-x: Bits 8-10 represent permissions that other users have, only read and execute.

Ls-al Indicates the meanings of each section in the output

drwxr-xr-x   4 oracle dba       4096 May 20 11:47 oralog1
Copy the code

Oralog1 is a directory containing 4 files (folders) owned by Oracle. The file size is 4096 bytes and was created at 11:47 on May 20. Oracle has read and write permissions. Users in the SAME DBA group as Oracle have read-only and execute permissions. Other users have read-only and execute permissions.

The details are explained as follows:

  • Field 1: File properties field

The file properties field consists of a total of 10 letters, with the first letter indicating the file type. Other parameter meanings are described above. Note that a directory, or folder, is a special file that holds information about other files and folders.

There are several types of files

'd' is a directory file 'l' is a link file '-' is a regular file 'p' is a pipeCopy the code
  • Field 2: Number of file hard links or directory subdirectories
  • Field 3: file owner
  • Field 4: The group of the file owner
  • Field 5: File File size (in bytes)
  • Field 6: Month of file creation
  • Field 7: File creation date
  • Field 8: File creation time
  • Field 9: File name (if it is a symbolic link, there is a “->” arrow followed by the file it points to)

Note: Volume can be shown in readable units by lS-H. -h is –human-readable

Modify the operation permission of a filechmod

If you need to change the permissions on a file, you use the chmod command. It is simple to use as follows:

chmod options fileName
Copy the code

This command performs operations on fileName according to the options configuration. There are two configuration modes.

Input control through the symbols character symbol

chmod u=rwx,g=rx,o=r myfile
Copy the code

The above operation means to change the permission of myfile so that the owner of the file can read and write, its user group can read and execute, and other users can only read. Here’s the explanation:

  • The letteru,goOn behalf ofuser,group,other.
  • The equal sign (=) to assign the corresponding permissions.
  • The letterr,w,xRepresent theread,writeexecute.
  • A comma is used to separate the permissions of different users without any space between them.

It is controlled by octal numbers (0-7)

The above operations are equivalent to:

chmod 754 myfile
Copy the code

Why is that? Here’s why:

The numbers 7, 5, and 4 respectively represent the permissions of user, group, and Others. Each number is the sum of four numbers: 4, 2, 1, and 0.

  • Four representative to readread
  • 2 for writingwrite
  • 1 represents executionexecute
  • 0 indicates no permissionno permission

So 7 is the sum of 4+2+1 (read, write, execute), 5 is 4+0+1 (read, no write, execute), and 4 is 4+0+0 (read, no write, no execute).

Summary thanks

This paper mainly studies:

  • Concepts of user groups and root users
  • File permission view command
  • Command for modifying file permissions

After studying, you will understand what the common 777 stands for.

This article has the following link, thanks to:

  • Linux chmod command
  • course-shell
  • -rwxrwxrwx=777 -rwxrwx =777