Notes for file management in linux

Source: Internet
Author: User
Notes for file management in linux 1. what impressed me most about file permission management in linux is its permission management, which is much more flexible and strict than that in windows. it is also convenient for users. Using the ls-l command, we can see that the current folder...
Notes for file management in linux 1. what impressed me most about file permission management in linux is its permission management, which is much more flexible and strict than that in windows. it is also convenient for users. Using the ls-l command, we can see the file attributes in the current folder. There are 7 columns in total, including permissions, links, File owners, all file groups, file size, file modification date, and file name. Www.2cto.com

Let's look at these two hard-to-understand attributes: (1) permission attributes. This column represents the type and permission of the file, with a total of 10 characters. The first character represents the file type, -represents a common file, d represents a directory file, and l represents a link file, B represents a block interface device file, and c represents a serial interface device file, such as a keyboard or mouse, that is, the portable device file. The last nine characters indicate the permission information of the file. Three of them are regarded as a group and a total of three are considered as the group. R indicates readable, w indicates writable, and x indicates executable. their positions are not changed. If no response permission is available, it is represented by the symbol.
The first group of 2-4 characters represents the permissions of the file owner. in showinfo2, for example, for the owner cenkaijie5, it has the rw permission, but does not have the x permission, that is, it has the read permission, write permission, but not the execution permission. The second group contains 5-7 characters, which indicates the permissions of all groups of files. The third group contains 8-10 characters, which indicates the permissions of other users. for example, if showinfo2 is still used, r -- indicates that other users only have the read permission on the showinfo2 file.
(2) number of connections attribute, which indicates how many files are the same as the current file. for ext2 files, that is, they have the same inode number. For common files, whenever you create a hard link, for example, after the command ln user user2 is executed, the number of user connections changes to 2 because user and user2 both point to the same file, that is, it has the same inode number.
This is also true for directories. However, it is worth noting that the number of links to a directory must be at least 2. Because every time you create a directory, two Directory files are created under this directory. and .., directory file. the same inode number as the newly created directory, directory file .. it has the same inode number as the parent directory of the newly created directory. Therefore, each time you create a directory, the number of links to this directory is 2, and the number of links to the parent directory is 3, so we can see that for directory file download, the number of links is 5, indicating that it has three Directory files.

II. next we will discuss the meaning of permissions on directories and common files. This part is easy to understand and may lead to deviations. we cannot simply regard directories and common files as the same.
1. for common files (including text files, jpg files in various formats, binary files, and so on), its data block stores real content and real data that people need, therefore, the permission is:
R read permission: You can read the actual content of this file. Www.2cto.com w write permission: you can modify, edit, and add the actual content of the file, but not the permission to delete the file. X execution permission: the permission that the file can be executed by the system.
2. for a directory file, its data block stores the file name list and the corresponding inode number. The file name has a strong relationship with the directory file because the inode table does not contain the file name. R read permission: indicates that data block content is available, that is, the file name list under the directory can be read.
W write permission: this means that the data block content can be rewritten, that is, files can be deleted and new files can be added. X execution permission: it means you can enter the directory to make the directory a working directory and read various attributes of the file list. When the www.2cto.com Directory has only the read permission, use the ls command. for example, you can only see the file name under the folder, but cannot see the file attributes. all the file attributes are placed in the inode of the file, instead of the data block in the directory

If the directory has only executable permissions, use the ls command. for example, you cannot see the content in the data block of the Directory, that is, you cannot see the file name and inode number.

However, if you know the file name TV under this directory and have the TV read permission, you can use cat cc/TV to view the file, as shown below:

For another example, how does the system read the cat/etc/passwd file? 1. inode of/finds the inode number of/2 through the information of the Mount point, and the inode record permission is r-x, so we can enter the/directory. The block of www.2cto.com 2./reads/data block to check whether there are etc files. Yes. inode 1912423 of etc is found. 3. the inode record permission of etc is r-x, so we enter the etc directory. 4. the block of etc reads the data block of etc to check whether there is a passwd file. Yes. inode 1914888 of passwd is found. 5. the permission for inode record of passwd is r --, so you can read the data block content of passwd 6. read the last data block content of the passwd block. To sum up, I understand that (1) The x permission of the directory is required and the most important permission. You do not have permission to access directory x. You cannot access this directory. you cannot delete or add or modify new files. View and execute existing files, you can only query the list of file names in the directory at most. No directory x permission, almost no movement.
(2) the directory's r permission is not mandatory. with the r permission, you can use the ls command to query the list of file names in the directory. if you do not have the r permission, you may still modify, view, and execute files. (3) The w permission of the directory is used to create, delete, and rename a file. it must be combined with the x permission; otherwise, the permission is invalid. Www.2cto.com 3. What is the difference between a hard link and a soft link? a hard link uses an inode number to connect to a file. it does not occupy an additional inode number. only one table entry is added to the datablock of the directory file. A soft link is also called a symbolic link. it is more commonly used than a hard link. it is a special file type. it uses a file path to link to another file, instead of directly linking to inode.
1. hard links are implemented based on inode. because the inode number is unique and the inode numbers of different file systems are inconsistent, hard links cannot be implemented across file systems. soft connections are implemented based on paths, so cross-File System 2. in linux, hard links cannot be connected to directories (except for the system. and .. these two special cases), while soft links can. To sum up, soft links are more commonly used.

 
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.