File and Directory permissions resolution for Linux

Source: Internet
Author: User
Tags aliases

In Linux , everything is files, ordinary files are files, directories are files, hardware devices are files, so learning to understand The files in Linux is very important.

  Linux There are three types of files in:

(1) ordinary documents: also divided into text files and binary files

(2) catalog file: A directory file stores information about the location, size, and so on of a set of related files.

(3) device files:I/O devices are also treated as files in Linux , as with normal files, so that the file and device operations are as uniform as possible.

One, Linux file Properties

linux Span style= "FONT-FAMILY:CALIBRI;" >ls -l command, in order to follow the instructions in the operation of the permissions, the following contents are as follows root root ubuntu ( All of the following are in ubuntu ) root -s and then enter the password to get root permissions.

We can see that after getting the root permission, it becomes #, which is the flag that gets root permission.

OK, we enter ls-al, we can see the details of all the files ( including hidden files and directory files ) under the user directory .

Every line has a bunch of stuff, what does it mean? Rookie said do not understand the embarrassed RZ, don't worry small Hu start also what all can not understand, patience to see the next content, read I guarantee you think so easy !

Before formally introducing these things, Xiao Hu first to tell you about ls this command.

Command:ls

Function: Displays the directories and files for the specified directory.

Common parameter options:

- L lists the detailed properties of the files under the specified directory

-A lists all files in the specified directory, including hidden files, i.e. . the file that starts with

-D lists all directories under the specified directory, noting that the directory is not a file

- k in K the form of a byte represents the file size

- I. Display the index node of a file

- R Displays the contents of the specified directory and sub-directory

- T sort by create or last change time

- S Sort by file size

Note that these parameters are optional, and if you just type ls, only all the files in the current directory (without hidden files) will be displayed. Optional parameters can be reused, for example, we use ls-l to display the details of all the files in the current directory, with ls-a display all the files in the current directory (including hidden files), If we want to show the hidden file and want to display the file information, then we can use ls-la or ls-la(parameters in no particular order), the same reason, When we want to display all the file information in chronological order, we can use ls-tl or ls-lt, the combination of other commands and so on, according to the needs of the free combination, the following shows some of the command , more dozen dozen, soon know how to use.

I'm sure we can use the LS command. If the action is to forget what parameters or what the role of a parameter, then type man ls, there is a detailed analysis oh. OK, next we get to the point, using ls to display the file attributes, then no line of information in what meaning? Don't worry, and listen to Xiao Hu to explain!

We follow each of the columns to explain.

The first column represents the type and permissions of the file

In the first column, the first letter indicates whether the file is a directory, a file, or a linked file.

  D represents a directory

- represents a file

L = Link file (linkfile)

b indicates the storage interface device inside the device file.

  C represents a serial port device inside a device file, such as a keyboard, mouse

  P Pipeline Files

  s Socket file

After the 9 characters, we have a group of 3, in each group,R represents the Read permission,W represents the Write permission, andx represents the executable permission. The first group represents the permissions of the owner of the file, the second group represents the permissions of the user group where the file owner resides, and the third group represents the permissions of the other users, and we take the paas.sql file in the penultimate line as an example to see the first letter we know it is a real file, The file owner has read and write permissions, the owner of the user group has read and write permissions, the other users have access only, and everyone does not have the executable permissions of the file.

The second column represents how many file names are connected to this node

In layman's words, this is how many file aliases this file has, which is a bit like a reference variable in a programming language, although the aliases are different, but they point to the same file.

The third column represents the user name of the file owner

The fourth column represents the group name of the user group where the file resides

The fifth column indicates the size of the file, and the default unit is B

The sixth column indicates the date the file was created or the most recent modification date

The seventh column is clearly the file name.

Summary: We still take the paas.sql As an example, the authority said, it has a file name, the owner is Codeman, the owner of the user group name is also Codeman , the file size is 2272B created or the last modified time is 17 months Point One, the file name is paas.sql.

We notice that the file time shown above does not show the year, here we can use-full-time to show the detailed time, as follows.

about why you should set Linux file permissions?

Believe that a lot of beginners have such doubts, Xiao Hu began to useLinuxis no exception. Especially when I was doing a project,Lampenvironment Development, and then debugging often appear without permission to access the file problems, feel very annoying ah, and then the Internet Search command direct access to full open, in fact, this is stupid yes! We all know that.Linuxis inUnixafter that, it was designed to follow theUnixsystem Architecture Standards,Unixis designed for multi-user multitasking, when the same host is accessed by multiple people, how to protect the privacy of each user becomes a very critical issue, soUnixwith the user, user group, other users these three levels of permissions, to ensure the privacy of each user group of users, it is very useful, in addition, we knowLinuxis far more secure thanWindowsmuch higher, a very important reason is because there is a file permissions mechanism, any operation must have permissions, so it is more secure!

Ii. How to change file attributes and permissions

Through the above explanation believe that you have some concept of file permissions, then Xiao Hu will give you how to change the properties and permissions of the file.

There are three main commands to use:

chgrp : Change the user group to which the file belongs

Chown: Changing the file owner

chmod: Changing the permissions of a file

Change the owning user group:chgrp

# CHGRP [-R] Dirname/filename

Ps.-r represents a continuous change of recursion, which, along with subdirectories and files under the directory, also modifies the user group, and if the user group does not exist, an error will be made to see which groups of users in the system can view /etc/group.

As shown in, we create a test.txt file in the user directory , look at the file information, it belongs to the root user group, and then use chgrp to change test.txt belongs to the user group codeman, and then look at the file properties, we can see that the file belongs to the user group has become Codeman up.

Change file owner:chown

#Chown [-R] Dirname/filename

PS. usage as above, as well as users who already exist in the system to change, to see which users in the system can view /etc/passwd

Permissions to change files:chmod

There are two ways to set file permissions

(1) Number type change file permissions

Through the above study, we know that the file permissions for the user, user groups, other people have a total of three groups of permissions, we use 4 for R, 2 for w, 1 for x. Three numbers add up and represent a set of permissions, and three numbers represent the full permissions of a file.

# chmod [-R] 777 Dirname/filename

(2) symbol type change file permissions

Use u to represent user,g for group,o to indicate Others,a means all

Use + to join,-means to drop, = To set

Use r for reading,w for write,x for execution

eg:

# chmod U=rwx,go=rx Dirname/filename

Equivalent to chmod 755 dirname/filename

When Ugo Set the same permissions, can be written together, such as ugo=rwx, can also be written a=rwx

Add, remove a permission, and so on.

Third, directory and the meaning of the file permissions

(1) the importance of permissions to documents

  R (Read) : Can read the actual contents of this file

  W (write) : You can edit and add the contents of the modified file (without deleting the file)

  x (Execute) : In Windows File extension to determine whether the file can be executed, and Linux The file can be executed by the

Whether you have x permission to decide whether the file can be executed is not related to the extension.

(2) the importance of permissions to the directory

  R (Read contents in directory) : Represents a permission to read a list of directory structures

  W (Modify contents in directory) : Represents a permission to change the list of directory structures

  x (Access directory) : Indicates whether the user can enter the directory to become the working directory

Practical application:

To pay attention to the difference between file permissions and directory permissions, many times to successfully read and write to the file in addition to having permissions on the file, you also need to consider the user's permissions on the directory where the file is located, and if you do not have permissions on the directory, you will not be able to successfully manipulate the file.

Eg:

We are in the user directory toRootPermissions withmkdircommand creates aTestingfolder, withTouchthe Command folder has aTestingthe documents, respectively, given744and the -, and then switch the user toCodeman, so that the average user isTestingThe directory has a read permission, as previously said, it should have readTestingpermissions for the file properties under directory, but due to the general userTestingThe file does not have any permissions, and a bunch of question marks appear when you display the list of file attributes. Since there is no rightTestingthe executable permission of the directory, so the general user cannot switch the working directory toTesting.

The section on file and directory permissions is about this, and there are some flaws to be welcome!

File and Directory permissions resolution for Linux

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.