Basics of Linux Summary

Source: Internet
Author: User

ContactLinux about one weeks, I haveLinux is just a beginner's knowledge, just installed Ubuntu., others have not tried, just read a few books and videos, so summarize to let knowledge slightly order. 1.user and user groups

Linuxis a multi- user , multitasking operating system , which means that multiple people can use a single host at the same time. Because of each user's personal preferences and privacy issues, the file owner is particularly important. Dividing users into different groups is, of course, for ease of management. So there are three types of relationships between users and files: (1)User: Indicates that the user is the owner of the file. (2)Group: Represents the user and the owner of the file in the same user group. (3)Others: In addition to the other two types of users. In addition,LinuxThere is also a specialRootaccount, equivalent toWindowsin the Administrator account, ownership of all files.

because it's just a person who uses it on their own machine, there's no deeper understanding of this part. Because Linux is for multi-user, so permissions are particularly important, the focus is on file permissions.

2.file Permissions
2.1 Linux file properties

Perform "Ls-l" under Terminal to view the files of the current directory, the L parameter is used to display the properties of the file, here is an example and the corresponding property description:

—————————————————————————————————————————————

-rw-rw-r--1 Jerry Jerry 100 June 11:40 hello.c

User rights, connections, owner, user group, file size, modified date, filename

—————————————————————————————————————————————

Note: The file size is in units B

The beginning of the string "-rw-rw-r--" There are 10 characters, the first represents the type of file, the common is: [-] for the file, [d] for the directory, [l] for the link file, [b] represents the device, etc. The following nine are divided into three groups, representing the user,group,other of the three categories of permissions, [r] for Read permissions, [W] for Write permissions, [x] for execution permissions, [-] represents no permissions. Therefore, the above example represents the owner of the file, Jerry, and the user of the same group is readable and writable by the file. Other users are only allowed to read. All users do not have permission to execute.

2.2 Meaning of file permissions

As mentioned above, the user has three permissions for files such as R (Read), W (write), and X (execute). " everything is a file "in Linux, so sometimes it's confusing, especially for catalogs. The following is a detailed description of these three permissions for the directory:

R: Indicates that the user can view the contents of this directory, that is, you can use the "ls" command

W: Indicates that the user can modify the contents of the directory, including additions, deletions, renaming, etc.

X: Indicates that the user can enter the directory, that is, you can use the "CD" command

"R" and "W" are easy to understand for what we usually call " files ," and "X" is confusing, Can a text file also be executed? At this point, there is a big difference between Linux and Windows. Under Windows, executables are usually terminated with ". exe". Under Linux, whether the file can be executed is not related to the suffix name, but only with the X permission. However, whether it is Linux or Windows, only binary files can be executed. Therefore, although the text file under Linux and the X permission can also be executed, but the system only know the binary machine language, so it is possible to error errors without any effect.

To verify this, you can do a simple experiment by compiling a C language file with GCC, by default you will get a "a.out" file, rename it to "a.txt", and then execute "./a.txt", You will find that the program is still able to execute.

2.3 Changes to file permissions

To change the permissions of a file under Linux, you can use the following three commands:

Change owner:chown user filename

change user group:chgrp Group filename

Change the permissions:chmod, there are two ways to use:

(1) Digital law:

Three permissions corresponding to the number of r:4,w:2,x:1, the three categories of user permissions are the same as the three number and, for example, the above example, " -rw-rw-r--" into a number is: 664, to give three users to add Execute permission, then use " chmod 775 hello.c "

(2) Symbolic method:

chmod u/g/o/a +/-/= r/w/x filename

The above "u" means user, "G" means group,"o" means others,"a" means all

"+" means to increase the permissions,"-" for the removal of permissions,"=" means that the Set permission is

"Rwx" is of course the file's three permissions, you can write only one, you can also write multiple

Is still the above example, to hello.c all users plus execute permissions, then the command is "chmod a+x hello.c"

PS: The above command can be added with "-r" parameter to make a recursive change

2.4 Default permissions for files: umask

The above has explained the basic knowledge about file permissions, so when we create a new file, what is the permissions? This involves the file's default permissions: Umask. Enter umask under the terminal, will get a number, like on my machine is "0002", the last three numbers is the default permissions of the file, but note that this is the file default does not have permissions. That is , "002" means others does not have W permissions. It is also important to note that the files and directories are still different here. The file does not have X permissions by default, that is, the maximum permission is "-rw-rw-rw-", and Directory access requires X permissions, so the default maximum permission is "-rwxrwxrwx". So on my machine umask to "002", creating a file and a directory, respectively, the result is as follows:

Drwxrwxr-x. 2 Jerry Jerry 4096 August New

-rw-rw-r--. 1 Jerry Jerry 6 August 11:29 New.txt

To set the Umask, add the set number directly, such as "umask 022"

Ps:umask plus the "-s (uppercase)" parameter can directly display the file permissions, but do not distinguish between files and directories, such as my machine on the display "U=rwx,g=rwx,o=rx", Still be aware that the file does not have X permissions by default.

Basics of Linux Summary

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.