The attributes of a Linux file or directory mainly include: the node of the file or directory, the type, the permission mode, the number of links, the users and groups it belongs to, the time of recent access or modification, and so on. The details are as follows

usels -lihList the above information

> ls -lih
12939236190 drwxr-xr-x  3 mac  staff    96B  2 19 21:47 doc
  • Column 1: inode
  • The second column: file type and permissions
  • Column 3: Number of hard links
  • Column 4: By the Lord
  • Column 5: Group to which you belong
  • Column 6: Size of file or directory;
  • Column 7: Last modified time;
  • Column 8: Filename or directory name

inode

The inode is translated as an inode in Chinese. Every storage device or partition of a storage device (a storage device is a hard disk, a floppy disk, a USB flash drive, etc.) that is formatted into a file system should have two parts, one inode and the other Block, which is used to store data. The inode, on the other hand, is the information used to store the data, such as file size, owner, user group, read and write permissions, etc. The inode indexes the information for each file, so you have the value of the inode. The operating system is instructed to find the corresponding file the fastest by inode values.

Hard links

In the Linux file system, a file stored in a partition on disk, regardless of its type, is assigned a number, called an Inode Index, which is the unique identification of the file or directory in the Linux file system. With this number, you can look up the details of the file.

At the same time, Linux also stipulates that multiple file names can be allowed to refer to the same Inode at the same time, which is a hard link. Such design have one advantage is that, as long as the file’s index node also has more than one link, delete one of the link does not affect the index node itself and other entities (that is, the file is not deleted), and only when the last link to be deleted, and now has new data to be stored to disk, Only then will the deleted file’s data block and directory link be released, and the storage space will be overwritten with new data. Therefore, this mechanism can effectively prevent accidental deletion.

Hard links can only be linked within the same type of file system, not across file systems. Also, it can only link to files, not directories.

Create a hard connection to the file

> ln rumen.txt rumenz.txt
> ls -lih
total 0
12940530535 -rw-r--r--  2 mac  staff     0B  2 19 23:01 rumen.txt
12940530535 -rw-r--r--  2 mac  staff     0B  2 19 23:01 rumenz.txt

Why is the number of hard connections to create a file in an empty directory 2

> mkdir rumenz
> ls -lih
12940530815 drwxr-xr-x  2 mac  staff    64B  2 19 23:03 rumenz

The reason is:
rumenzIt will be in the directory by default
.and
.Directory, representing the current directory and the parent directory, respectively

> ls -al rumenz
drwxr-xr-x  2 mac  staff  64  2 19 23:03 .
drwxr-xr-x  3 mac  staff  96  2 19 23:03 ..

The file type

  • – : Represents plain file
  • D: stands for directory
  • L: stands for soft connection (ln — s source file link file)
  • B: Block devices and other peripherals are special types of files

File permissions

  • R readable, number permission is 4
  • W is writable, number permission is 2
  • X is executable with numeric permission of 1

The three permissions (r/w/x) of each identity (owner /group /others) need to be added up. For example, when the permissions are: -rwxrwx– the score is:

  • owner = rwx = 4+2+1 = 7
  • group = rwx = 4+2+1 = 7
  • others= — = 0+0+0 = 0

The original link: https://rumenz.com/rumenbiji/… WeChat official account: entry station