Linux File Attributes

Source: Internet
Author: User

Linux File Attributes

 

Overview of file properties (ls-lhi)

Everything in linux is a file
Attributes of files or directories in Linux include: inode, file type, permission attribute, number of links, owner users and user groups, and last modification time:

Explanation:

Column 1: inode index node number (equivalent to a person's ID card, which is unique nationwide)
Column 2: file types and permissions
The second column contains 11 characters in total: the first character is the file type, the subsequent nine characters are the corresponding permissions of the file, and the last character is the ". "is an identifier related to selinux;
Column 3: Number of hard links (see the ln command for details );
It is equivalent to multiple portals in a supermarket. Different file portals can be used to access files and backup each other (fire-fighting channel)
Column 4: Owner (owner) of the user file to which the file or directory belongs );
In linux, files and programs must have users and groups to meet the corresponding requirements.
Fifth: the group to which the file or directory belongs
Column 6: file or directory size;
Column 9: file or directory modification time: Default month/day
Column 10: actual file or directory name
The file name is not an attribute of the file.

The following uses the chensiqi file as an example. For details about the column content, refer to the figure above:

1736707 -rwx-xr-x- 1 root root 35 Oct 28 11:29 chensiqi

  • Inode index node number1736707
  • File TypeThe file type is-, indicating that this is a common file;
  • File Permission: The File Permission is rwxr-xr-x, which indicates that the file owner is readable, writable, and executable. the user group of the file owner is readable and executable. Other users can execute the file.
  • Number of hard links: Indicates that the chensiqi file does not have any other hard links, because the number of connections is 1, which is itself;
  • File owner: The user to which the file belongs. This indicates that the chensiqi file is owned by the root user. Note that it is the first root user;
  • File Group: User group to which this file belongs. Here it is the root user group, which is the second root in the display information.
  • File Size: The file size is 35 bytes.
  • File modification time: The time here is the time when the file is last updated (including file creation, content update, and file name update). You can run the following command to view the file modification, access, and Creation Time:

 

Inodeinode Overview
  • To store data on a hard disk, you must partition the disk, format the file system, and mount the disk to save the data.
  • Inode, Chinese meaning index node ). Partition of each linux storage device or storage device (the storage device can be a hard disk, a floppy disk, or a USB flash disk ...) after it is formatted as an ext4 (CentOS6.8) file system, two parts are generally generated: The first part is Inode (many), and the second part is Block (many ).
  • This Block is used to store actual data, such as photos, videos, and other common file data.
  • Inode is used to store the data attribute information (that is, the result of ls-l). inode attribute information includes not limited to file size, owner (user), owner user group, file Permission, file type, modification time, And pointer function pointing to the object (inode node-block ing). However, inode does not include the file name itself. The file name is not in inode, and is generally in the block of the parent directory.

ID card No. === inode No.

  • In addition to recording file attribute information, Inode also performs information indexing for each file, so there is an inode value. Based on commands, the operating system can find the corresponding file entity with the fastest inode value. For relations between files, inode, and blocks, see:

If there is a book, storage devices and partitions are equivalent to this book, blocks are equivalent to every page of the book, and inode is equivalent to the directory before this book, a book has a lot of content, A knowledge point may contain multiple pages. If you want to find the content of a certain part or knowledge point, we generally first query the directory of the book to quickly find the content of the knowledge point we want to see. Although not appropriate, it is still a relatively good image.

When we use ls to view a directory or file-I ParametersYou can see the inode node:

【root@chengliang /】# ls -i

  • The inode value in the first column of the figure is 259615. You can view the inode of a file or directory by using the-I parameter of the ls command.
  • Because inode stores file attributes, each inode itself has a size. The default size of the Centos5 series inode is 128 bytes, while the default size of the Centos6 series inode is 256 bytes, the inode size is determined after the partition is formatted and the file system is created. After formatting, The inode size cannot be changed. Before formatting, you can specify the inode size through parameters, however, enterprise environments do not have this requirement.
  • Different Centos versions have different inode sizes.

View the total inode and remaining amount of the file system: df-I

View disk usage: df-h

Inode: attributes of the stored file + location of the file content (block location)

Block: stores actual data.

 

Enterprise case simulation: Simulate Disk Full

No space left on device)

1. The block is full and the disk space is full.

2. When inode is full, an inode is required to create a file.

Inode summary about Blocks

 

Enterprise interview question 1:

For a 100 M (100000 K) disk partition, how many files can be written into 1 K or 1 M respectively?

 
 
  • Although a 1 K file is small, the block size is generally 4 K by default. Even if the data size is 1 K, 4 K is occupied. For example, you can create an empty file and then du-sk to check the size. (If you think it should be 100000/4 at this time, then you will fall into the trap -_-! Don't forget to store data. It consumes not only blocks but also inode. By default, inode is only 256 kb (centos6). Each file occupies at least one block and occupies one inode)
  • The 1 m data can be split by 4. So there will be no waste of space, about 100, with sufficient inode. Generally, inode is sufficient for large files, and it does not waste much space. However, inode is insufficient for small files, therefore, the quantity that can be stored is the number of inode.
Enterprise interview question 2:

If the following error is prompted when writing data to the disk: No space left on device. Check the disk space through df-h and find it is not full. What is the possible cause? Under what circumstances does an enterprise cause this problem?

If the disk is not full but cannot be detached, the most likely reason is that inode is exhausted.
In enterprise work, the temporary mail queue/var/spool/clientmquene or/var/spool/postfix/maildrop is easily occupied by a large number of small files, leading to the error of No space left on device. The clientmquene directory is a temporary queue of sendmail only when the sendmail service is installed. Sendmail is installed in centos5.8 by default. By default, no sendmail is installed in centos6, but postfix is available.

 

Introduction to file types and extension file types
  • The windows extension allows the system to differentiate different file types. If the extension is incorrect, the file cannot be opened.
  • Linux uses the extension to differentiate file types. errors can also be used for ease of reading.

For example:

Windows Image File Extensions: jpg, jpeg, png, and gif
Text File Extensions: doc, docx, txt, pdf

 

File Types in Linux

It seems that it is of little significance to the actual application. You only need to know how to view the Directory through ls-l.

If the permission is-rw -- r --, the first character is '-', which indicates a common file.
If the first character is d, for example, drw -- r --., it indicates a folder.
If the first character is l, for example, lrw -- r --, it indicates a soft link.

 

Functions of Linux Extension

In linux, although the extension does not make much sense, in order to be compatible with windows, at the same time, it makes it easier for most windows users to differentiate files, we are still used to express the types of different files through the extension.

As follows::

Reference blog: http://www.cnblogs.com/chensiqiqi/p/6247146.html

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.