Linux Series Tutorials (v)--linux link commands and Rights management commands

Source: Internet
Author: User
Tags touch command file permissions

The previous blog we explained the Linux file and directory processing commands, or Laosheng Changtan, for beginners, we do not need to fully remember the command of the detailed syntax, remember what the command can be done, and then need to check the good, with the more we will naturally remember. In this blog we go on to the Linux commands--Link commands and Rights management commands.

1. Link command one, generate link File command: ln

①, command name: LN

② and English original meaning: link

③, command path:/bin/link

④, execute permissions: All Users

⑤, Function Description: Generate link file

⑥, Syntax: ln-s "source file" "Destination file"

-S Create soft links

Create a hard link without the-s

Example: a soft link to create a file/etc/issue/tmp/issue.soft:ln-s/etc/issue/tmp/issue.soft

Second, create the file/etc/issue hard link/tmp/issue.hard:ln/etc/issue/tmp/issue.hard

   

We can see:

First: The soft link is preceded by the L (link), and the hard link is-begins, representing the file

Second: The soft link owner and the owning group have full operation permissions, rwxrwxrwx, and hard links are not. That is, the soft link is preceded by lrwxrwxrwx.

Third: Soft links are similar to Windows shortcuts, with an obvious arrow pointing to the source file

IV: Hard-link files except the file name is not the same as the source file, all the rest of the information is the same. Similar to the CP copy operation. However, unlike replication, hard links can be updated synchronously.

V: Through the ls-i operation, to view the file's I node. The I node of the hard link and source file is found to be the same, and the soft link is different from the I node of the source file

Sixth: Hard links are not allowed to be directed to directories, and hard links cannot be created across partitions

  

2. Rights Management Command One, change file or directory Permissions command: chmod

①, command name: chmod

②, English original meaning: Change the permissions mode of a file

③, command path:/bin/chmod

④, execute permissions: All Users

⑤, Function Description: Change file or directory permissions

⑥, Syntax: chmod "{ugoa}{+-=}{rwx}" "File or directory"

"mode=421" "File or directory"

-R Recursive modification

Note: Not every Linux user has permission to change a file or directory permission, only two users can change file or directory permissions

①, the owner of the file. We can see the file's owner by looking at the details of a file with the LS command.

②, root user, needless to say, the root user is the most privileged user of the Linux system. The root user is capable of doing things that no one else can do.

  For the above syntax chmod "{ugoa}{+-=}{rwx}" "File or directory", we want to know that Ugoa is: U: Represents the owner, G: Indicates the owning group, O: Represents the other person, a: represents everyone. And rwx means the following:

  

For "mode=421" "File or directory", this is our permission to be represented by a number, where r means that the 4,w means that 2,x represents 1, respectively, 2 0, 1 times, 2 parties. Then we can understand that: the number with rwx permission is 7, the number with rw-permission is 6, the number with r--permission is 4.

Example 1: We give permission to the Tmp.log owner X under the TMP directory, to the owning Group W permission, to the other person W permission.

chmod U+x/tmp/tmp.log

chmod G+w,o+w/tmp/tmp.log

  

Change the above example to use a number to operate, that is, we want to give Tmp.log the file permission is rwxrw-rw-, the number is 766. chmod 766 Tmp.log

  

We can also give permissions recursively, that is, add the-r parameter to all files or directories under the specified directory to give the specified permissions.

Example 2: Granting 776 permissions to all files and directories under the TMP directory

Chmod-r 776/tmp

  

Ii. changing the file or directory owner command: chown

①, command name: Chown

②, English original meaning: Change file ownership

③, command path:/bin/chown

④, execute permissions: All Users

⑤, Function Description: Change the owner of a file or directory

⑥, Syntax: chmod "user" "File or directory"

  Note: The owner user who can change the file or directory is root

Here we create the user by Useradd the "username" command and then enter the password by passwd "user name", which will be followed. We create VAE users with these two commands

  

We then changed the owner of the Tmp.log to VAE users: Chown vae Tmp.log

  

Third, change the file or directory belongs to group command: CHGRP

①, command name: CHGRP

②, English original meaning: Change file group ownership

③, command path:/bin/chown

④, execute permissions: All Users

⑤, Function Description: Change the owning group of a file or directory

⑥, Syntax: chgrp "user Group" "File or directory"

  Note: The owner user who can change the file or directory is root

Iv. Displaying and setting default permissions for files command: umask

①, command name: umask

②, English original meaning: the user file-creation mask

③, command path: Shell built-in commands

④, execute permissions: All Users

⑤, Function Description: Display, set default permissions for files

⑥, Syntax: umask "-S"

-S Displays the default permissions for new files in rwx form

  Note: You may not understand the meaning of this command, we perform umask and umask-s separately, as follows:

  

Where umask execution shows the result is 0022, the first 0 represents special permissions, and we will explain separately what kinds of special permissions. 022 represents the mask value of the permission, we use 7 7 7 minus 0 2 2 to get 755 (is each bit subtracted), that is, the following by adding the-s output of the rwxr-xr-x, this value is represented by a number is 755.

This means that the default permission to create a file is rwx, the owning group is RX, and the other man is Rx. In other words, creating a new file with default permissions of Rwxr-xr-x, we create a file to verify:

  

We found that using the touch command to create a file a.txt, and then found that the permissions are not rwxr-xr-x, but Rw-r--r--。 The comparison found that three X is missing, that is, the executable permission is less. What is this for?

This is because in a Linux system, all newly created files are not executable permissions. This is a kind of self-protection of Linux system, because similar virus trojan program has the executable permission. Therefore, in a Linux system, the newly created files are not executable permissions.

So how do we set default permissions? For example, we want to set the newly created file permissions to rwxr-xr--, which is 754. We use 777 minus 754 to get 023. That is, the default permission settings are completed by executing umask 023来.

  

  

3. Summary

In this article we explain the link command Ln and the Rights management commands. First of all, for the link command, we should note that ln-s means to create a soft link, do not add-s to create a hard link, we need to note the difference between soft links and hard links, soft links similar to Windows shortcuts, there is an obvious arrow pointing, and pointing to the source file. and hard links we can imagine as Cp-p + synchronous update, that is, create a hard link and the original file to maintain the same properties, and the original file changes, hard links will also change.

Then we introduced a few rights management commands, for the permissions, we say enough good, many novice in the permission operation is, up is chmod 777 "file or directory", so although it is not easy, but obviously not accurate, chmod command can change the file or directory permissions, The chown command can change the file or directory owner, and the CHGRP command can change which group the file or directory belongs to. We need to note that the following two commands can only be done by the root user, and the chmod command can be done in addition to the root user, and the owner of the file or directory has been changed.

Linux Series Tutorials (v)--linux link commands and Rights management commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.