Linux Everything in the system is a file , We use commands ls -li When looking at documents , Can display the specific information of the file , There are nine columns , Each column has a different meaning .

linux File attribute information analysis (inode/ jurisdiction / Hard connection, etc )

File attribute

file inode

Files are stored on the hard disk , The smallest unit of hard disk storage is called sector sector, Each sector stores 512 byte . When the operating system reads the hard disk , Not sector by Sector , That's inefficient , Instead, read multiple sectors continuously at once , That is, read one block at a time block. This block of multiple sectors , Is the smallest unit of file access . The size of the block , The most common is 4KB, Eight in a row sector Form a block.

File data is stored in blocks , Then you have to find a place to store the meta information of the file , For example, the creator of the file 、 Date the file was created 、 File size and so on . The area where the meta information of a file is stored is called inode, It's called index node in Chinese , Also called i node . therefore , One file must occupy one inode, But at least one block.

  • Meta information → inode
  • data → block
# stat Commands can be viewed inode Information
[[email protected] ~]# stat /etc/passwd

 

linux File attribute information analysis (inode/ jurisdiction / Hard connection, etc )

inode Information

file type

The common file types are as follows :

  • d: Representative directory
  • -: On behalf of ordinary documents
  • l: For linked files ( amount to windows System shortcuts )
  • c/b: Represents a block file / Character file
  • s: representative socket file ( Socket file )
[[email protected] ~]# ls -l /etc/hosts
[[email protected] ~]# ls -ld /etc/
[[email protected] ~]# ls -l /etc/system-release
[[email protected] ~]# ls -l /dev/zero 
[[email protected] ~]# ls -l /dev/sda

linux File attribute information analysis (inode/ jurisdiction / Hard connection, etc )

Different file types

File permissions

linux The basic permission bit of the file is 9 Bit permissions , In groups of three , They are the owner of the document (Owner) The reading of 、 Write 、 perform , The file belongs to the group (Group) The reading of 、 Write 、 perform , Other users (Other) The reading of 、 Write 、 perform ; And then there's the extra 3 Bit permission bit , common 12 Bit permissions .

Basic authority :

  • r : read (read) jurisdiction , You can use numbers 4 Express
  • w: Write (write) jurisdiction , You can use numbers 2 Express
  • x : perform (e'x'cute) jurisdiction , You can use numbers 1 Express
  • -: No authority , You can use numbers 0 Express
#  Create a new file , Generally, the default is 644 jurisdiction
[[email protected] ~]# touch testfile.txt
[[email protected] ~]# stat testfile.txt
#  Create a directory , Generally, the default is 755 jurisdiction
[[email protected] ~]# mkdir testdir
[[email protected] ~]# stat testdir
#  In fact, the default permissions for created files and directories , It's based on our system settings umask Is determined by the value of .
#  The default permissions for directories are :777   The default permissions for files are :666
#  According to the directory default permissions and umask Get permission to create a new directory by subtracting the weight of
#  According to the file default permissions and umask To get permission to create a new file
#  such as root User umask yes 0022, So directory permissions :777-022 = 755   File permissions :666-022 = 644
[[email protected] ~]$ umask 
0002

linux File attribute information analysis (inode/ jurisdiction / Hard connection, etc )

Default permissions

Special privileges :

suid It means that if a user is interested in his own shell The script sets this permission , Then other users will have the corresponding permissions of their owners when executing this script .guid It means that the user executing the corresponding script will have the permissions of the user in the user group to which the file belongs .

  • suid: User's corresponding permission bit , You can use numbers 4 Express
  • sgid: Permission bits corresponding to user groups , You can use numbers 2 Express
  • sticky: Permission bits corresponding to other users , You can use numbers 1 Express
# chmod  Commands can be used to set file permissions
#  Set up suid
[[email protected] ~]# chmod u+s testfile.txt
[[email protected] ~]# chmod 4644 testfile.txt
# Set up sgid
[[email protected] ~]# chmod g+s testdir/
[[email protected] ~]# chmod 2755 testdir/
# Set up sticky
[[email protected] ~]# chmod o+t /tmp/tmp.txt
[[email protected] ~]# chmod 1644 /tmp/tmp.txt

linux File attribute information analysis (inode/ jurisdiction / Hard connection, etc )

Special privileges

Number of file hard connections

Hard connection is a inode Value corresponds to more than one file name , It's equivalent to using multiple aliases , Hard links can only link between files in the same file system , Cannot create directory . Deleting a hard link file does not affect others having the same inode Document No .

#  Create a file , Content hello world
[[email protected] ~]# cat > myfile.txt 
hellp world!
^C
#  see inode, The number of hard connections is 1
[[email protected] ~]# ls -li myfile.txt 
67153474 -rw-r--r--. 1 root root 13 Jan 31 10:43 myfile.txt
# ln  Create a hard link
# ln  Source file   Target file
[[email protected] ~]# ln myfile.txt myfile.txt_1
#  Look at two files ,inode identical , The number of hard connections is 2
[[email protected] ~]# ls -li myfile.txt*
67153474 -rw-r--r--. 2 root root 13 Jan 31 10:43 myfile.txt
67153474 -rw-r--r--. 2 root root 13 Jan 31 10:43 myfile.txt_1
#  Delete source file , Does not affect the catalog file
[[email protected] ~]# rm myfile.txt -f
[[email protected] ~]# cat myfile.txt_1 
hellp world!
[[email protected] ~]# ls -li myfile.txt_1 
67153474 -rw-r--r--. 1 root root 13 Jan 31 10:43 myfile.txt_1

linux File attribute information analysis (inode/ jurisdiction / Hard connection, etc )

 

The owner of the document

The user of the file , That is to say uid.

#  adopt  id  command , View user information
[[email protected] ~]# id root
uid=0(root) gid=0(root) groups=0(root)
#  create a file , The file belongs to root user , Corresponding to read and write permissions
[[email protected] ~]# touch tmp.txt
[[email protected] ~]# ls -l tmp.txt 
-rw-r--r--. 1 root root 0 Jan 31 10:57 tmp.txt

linux File attribute information analysis (inode/ jurisdiction / Hard connection, etc )

Belong to

File group

The user group to which the file belongs , That is to say gid.

#  adopt  id  command , View user information
[[email protected] ~]# id root
uid=0(root) gid=0(root) groups=0(root)
#  create a file , The file belongs to root User group , Members of this group have read access to the file
[[email protected] ~]# touch tmp.txt
[[email protected] ~]# ls -l tmp.txt 
-rw-r--r--. 1 root root 0 Jan 31 10:57 tmp.txt

linux File attribute information analysis (inode/ jurisdiction / Hard connection, etc )

Generic group

Document capitalization

#  Create a file , size 25M
[[email protected] ~]# dd if=/dev/zero of=./test.txt bs=1M count=25
25+0 records in
25+0 records out
26214400 bytes (26 MB) copied, 0.176295 s, 149 MB/s
# ls  You can see the file size , Unit byte (bytes)
[[email protected] ~]# ls -l test.txt 
-rw-r--r--. 1 root root 26214400 Jan 31 11:10 test.txt
# du  Command to view the file size
[[email protected] ~]# du -sm test.txt

linux File attribute information analysis (inode/ jurisdiction / Hard connection, etc )

file size

File modification time

Linux System files have three times ,Access Time( Access time )、Modify Time( Modification time )、Change Time( Change time ).

  • Access Time, It's in Linux In the file system called access time , When the contents of a file are accessed , This time will be updated .
#  Create a time
[[email protected] ~]# echo 123 > tmp.txt
[[email protected] ~]# ls -l tmp.txt 
-rw-r--r--. 1 root root 4 Jan 31 11:23 tmp.txt
[[email protected] ~]# date 
Sun Jan 31 11:31:57 CST 2021
#  After looking at this file , You can see that the file access time has been modified
[[email protected] ~]# cat tmp.txt 
[[email protected] ~]# stat tmp.txt

linux File attribute information analysis (inode/ jurisdiction / Hard connection, etc )

Access Time

  • Modification Time, When “ Content data ” When modified ,Linux The system will update this time
[[email protected] ~]# ls -l tmp.txt 
-rw-r--r--. 1 root root 4 Jan 31 11:23 tmp.txt
[[email protected] ~]# date 
Sun Jan 31 11:34:43 CST 2021
#  Modify file content , The file modification time has been changed
[[email protected] ~]# echo 456 > tmp.txt 
[[email protected] ~]# ls -l tmp.txt 
-rw-r--r--. 1 root root 4 Jan 31 11:34 tmp.txt
[[email protected] ~]# stat tmp.txt

linux File attribute information analysis (inode/ jurisdiction / Hard connection, etc )

Modification Time

  • Change Time, State time , This time will be changed when the state of the file, that is, the attributes of the file, is changed , For example, in the file system links( Link number )、size( File size )、 File permissions .
[[email protected] ~]# ls -l tmp.txt 
-rw-r--r--. 1 root root 4 Jan 31 11:34 tmp.txt
[[email protected] ~]# date
Sun Jan 31 11:37:13 CST 2021
#  Create a hard connection for the file
[[email protected] ~]# ln tmp.txt tmp.txt_1
#  At this time, the contents of the file are not modified , The file modification time remains unchanged
[[email protected] ~]# ls -l tmp.txt
-rw-r--r--. 2 root root 4 Jan 31 11:34 tmp.txt
#  Use stat You can see that the state time has changed
[[email protected] ~]# stat tmp.txt

linux File attribute information analysis (inode/ jurisdiction / Hard connection, etc )

Change Time