Linux commonly used command learning (3)

Today is the third day of learning common commands

The first is the first command chmod: change the permissions mode of a file, to change file and directory permissions. Let me talk about it here again, u: owner, g: belonging group, o: others, a: everyone (a collection of the first three categories); r: readable, w: writable, e: executable

Insert picture description here
I am here to pass the command: chmod u+x,or,g=rw Japanlovestory.list, to modify the permissions of Japanlovestory.list, add executable permissions to the owner, and reduce the readable permissions to others, and give them Group operations are read and write permissions.

  • In addition to this method, you can also change the authority by entering the number converted from the binary number. r = 4, w = 2, x = 1: It can be understood as the (0, 1, 2) power of 2 rwx = 7, rw = 3, and so on
    Insert picture description here
    , the permission of Japanlovestory.list is changed through 777, and this number is changed Permissions, I hope to focus on this method, which is often used when learning shell scripts later.
  • chmod -R: Recursive modification. Suppose there is such a directory /tmp/a/b. If you only change the permission of directory a, you can actually find that directory b under directory a will not change. Therefore, if you want to change the permissions of this directory and all files in the directory, This format can be used.
    Insert picture description here
    Here we first create a directory a, create a file b in directory a, and find that the permissions of directory a and file b are different. Here, the permissions of directory a are changed through chmod -R 777 a, and you can find The file b under the directory a will also change accordingly.

Be sure to pay attention to the permissions of files and directories. Generally, the file will not be executed by w at the beginning. This is to prevent some virus files from being executed, so it is not executable by default and requires the user to manually open the execution permission. Secondly, it should be noted that whether a file can be deleted does not depend on whether the file has the w operation, but on whether the permissions of the directory where the file is located have the w operation.

For files For the catalog File operations Directory operations
r Can view file content Can list the contents of the directory cat/more/head/tail/less ls
w Can modify file content Can create and delete files in the directory vim touch/mkdir/rmdir/rm
x Executable file Can enter the catalog script command cd

Then the second command chown: change the owner of the file (only the root administrator can change the owner)

Insert picture description here
Here I use chown shenchao /tmp/fengjie command to change the owner of the fengjie file from root to user shenchao. This command can only be used by root!

Then there is the third command chgrp: change file group ownership (this command can only be used by root)

Insert picture description here
Here I changed all the groups in the Feng sister file to lampbrother

Then there is the fourth command umask: create basic settings

For example, if you want to set the basic setting of the
directory to the directory: rwx r-- r–
then the file is to delete the w operation in the directory: rw- r-- r–
will
perform non-operation with the maximum authority: rwx rwx rwx :--wx- wx, converted to a number: 033,
finally execute umask 033
Insert picture description here

  • umask -S: Display the default permissions of newly created files in the form of rwx. Usually the directory permissions are rwx-rxrx and the file permissions are rw-r–r--it is found that each location has less x execution permissions. This is to prevent some viruses file is executed, the default is to perform, require users to manually open the executing authority
    Insert picture description here
    went on to say what additional commands in the process of understanding, you can find out
  • useradd: add user
  • groupadd: add a group
  • su: switch user change user

Guess you like

Origin blog.csdn.net/MrChen666/article/details/113062217