This is the 8th day of my participation in the August More Text Challenge. For details, see:August is more challenging

Management command chmod

  • Linux system is a typical multi-user system. Different users are in different positions and have different permissions. To protect system security, the Linux system sets different permissions for different users to access the same file (including directory files).
  • File invocation permissions are divided into three levels: file owner, group, and others. How about using chmod to control files

Called by someone else.

View the file permission ls -l or ll == To change the file permission, you must be the owner of the file or root==

Grammar:

chmod [-cfvR] [--help] [--version] mode file... # below command is chmod starting mode mode = [{ugoa} {+ - =} {RWX}] chmod [{ugoa} {+ - =} {RWX}] [folder or directory]Copy the code

Parameter description: Parameter:

  • -c: Displays the change action only when the file permission has been changed
  • -f: Do not display an error message if the file permission cannot be changed
  • -v: displays detailed information about permission changes
  • -r: Make the same permission change for all files and subdirectories in the current directory (that is, change them one by one in a recursive way)
  • –help: display auxiliary instructions (front is two –)
  • –version: displays the version

Mode: permission setting string in the following format:

[ugoa…] [[+-=][rwxX]…] [,…]. Parameter Meaning of mode:

  • U indicates the owner of the file
  • G is the person who belongs to the same group as the owner of the file
  • O is for someone other than yourself
  • A means all three
  • + indicates adding permission
  • – Cancels the permission
  • = indicates the unique set of permissions (== Regardless of the previous permissions, the current set of permissions is treated ==)
  • R means readable
  • W indicates writable
  • X means executable (== executable is not ==)
  • X means only if the file is a subdirectory or if the file has been set to be executable.

The current permission information of file AAA is as follows:

  • Permissions of the owner userwin rw- (read 4 write 2)
  • Permissions of userwin group Rw – (read 4 Write 2)
  • Permissions for other user groups r– (Read 4)

Chmod u+x file: adds execution permission to the owner of file

Chmod g+x file: adds the execution permission to the owning group of the file

Chmod o-r file: disables other users from reading the file

Chmod u+wx,g+wx,o-r file Adds write and execute permissions to file owners and user groups, and removes read permissions from other users

Chmod o= RWX file Changes the permissions of other users to read, write, and execute the file

Chmod [-cfVR] [–help] [–version] mode file1 file2 Specifies the permission to modify both file1 and file2

== In Linux, you do not use the method of adding or subtracting file permissions. You usually use the numeric operation ==

Chmod 755 file Changes the permissions of the file to: the owner can read, write, and execute the file, the user group can read and execute the file, and other user groups can read and execute the file

The file permission is 777, why can’t delete the file?

== The permission to delete a file depends on the permission of the folder where the file resides and whether the current user has write permission on the folder where the file resides. = =Example: