In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the Linux inode information how to view the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Linux inode information how to view the article will have a harvest, let's take a look at it.
Inode is determined in file system creation, and each file system has an inode collection. The maximum directory size depends on the file system. For better performance, files are usually placed in different subdirectories instead of all files in the same directory.
What is inode number?
Inode is an entry in inode table that contains metadata about directories and regular files. Inode is a data structure on a traditional Unix-style file system such as ext3/ext4. Linux extension file systems, such as ext2/ext3, maintain an array of inode: inode table. Inode table contains a list of all files in the file system. Each inode entry in inode table has a unique number (the file system is unique), that is, inode number. Digging into the inode data structure, we find that it stores the following information:
File type: ordinary files, directories, pipes, etc. Permissions: readable, writable, executable links: number of hard links linked to the inode User ID: file owner Group ID: owner group ID file size time information attribute: for example, unchangeable bit access control list file data storage actual location other metadata
Note: file name data is not stored in inode
How to view inode information
If you want to view the inode information of the file system, you can use some shell commands to view the properties of the file system
a. Displays the specified file information
You can use the stat command to display inode information for a file or directory. You must specify a file or directory name.
# stat log.txt File: 'log.txt' Size: 21212 Blocks: 8 IO Block: 4096 regular fileDevice: fd01h/64769d Inode: 591912 Links: 1Access: (0644Mae RWMUR root -) Uid: (0 / root) Gid: (0 / root) Access: 2018-11-26 11MAV 2715 13.683598803 + 0800Modify: 2018-12-06 17181449.799424595 + 0800Change: 2018-12-06 17-18 49.799424595 + 0800Birth:-
The output of the command tells you all kinds of time information about the file, its ownership and permissions, and the location of the file. The block information on which the file data is stored is also shown in the output of the stat command.
You can also choose to list only the inode number of the file:
# stat-format=%i log.txt591912b. Print the inode number of the file
The ls command is used to list information about files / folders. The parameter-I indicates that the inode number of each file needs to be displayed. We can use it with the parameter-l to list the details:
# ls-litotal 16592404 drwxr-xr-x 6 root root 4096 Nov 2 15:01 config591900-rw-r--r-- 1 root root 453 Nov 25 22:25 docker-compose-single.yml592414-rw-r--r-- 1 root root 2714 Nov 2 15:01 docker-compose.yml592415 drwxr-xr-x 2 root root 4096 Nov 2 15:01 mariadb
The first column of the output shows the inode number of the file.
c. Displays the usage information of the file system inode
By default, the df command summarizes the available and used disk space. You can receive inode reports about available and used inode by passing the-I or-- inodes options.
# df-iFilesystem Inodes IUsed IFree IUse% Mounted onudev 2032387 398 2031989 1% / devtmpfs 2037595 1224 2036371 1% / run/dev/vda1 3276800 325180 2951620 10% / tmpfs 2037595 7 2037588 1% / dev/shmtmpfs 2037595 4 20375911% / run/locktmpfs 2037595 16 2037579 1% / sys/fs/cgroupoverlay 3276800 325180 2951620 10% / var/lib/docker/overlay2/c1955f95c338497d2f669ee0baf2706f93c2765001cafd3568b5af9ebfbe0dfd/mergedoverlay 3276800 325180 2951620 10% / var/lib/docker/overlay2/85a6ee4a64760a9e52efa312094092121160030132aaaf4bd32ecf5585324dfd/mergedoverlay 3276800 325180 2951620 10% / var/lib/docker/overlay2/692ed70766a4ee954c0f0f1b19d69b906c33ae54a618f8686f66e31e9ac05606/mergedshm 2037595 1 20375941% / var/lib/docker/containers/2a09d78972ebb74a7631dfd5e567a2b54282886ac8d8dc54dc1f5badffc692b8/mounts/shmshm 2037595 1 20375994 1% / var/lib/docker/containers/fd9619309707c1026876a401ac22eaf8dd9bfbaceb237ee927017818a6ffa3ff/mounts/shmshm 2037595 1 2037594 / var/lib/docker/containers/080d0d79e069041a2997dfaf2c07e69a0518ad44271dad4688f459958dac09c5/mounts/shmtmpfs 2037595 4 2037591.1 / run/user/1000
If the partition contains many small files, this information may be helpful, which may run out of available inode faster than running out of free disk space.
d. Lists information about file system super blocks
You can use the tune2fs-l command to display all the information related to inode.
# tune2fs-l / dev/vda1 | inode structure of the grep inodeFilesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent sparse_super large_file uninit_bgFree inodes: 2952348First inode: 11Journal inode: 8First orphan inode: 221187Journal backup: inode blocks directory
As mentioned above, directories in Linux are also treated as files. A directory is a special file that maps a file name to its inode number (this mapping is called dentry). So when we say that a directory contains files and other directories, we mean that the directory maps those files and directories to their inode number. This is why the directory cannot hold two files with the same name, because it cannot map a name using two different inode number.
When a file is mapped to inode through its parent directory, how does the top-most directory (that is, / directory) map to its inode? In fact, the inode number of the / directory is fixed, always 2.
# stat / File:'/ 'Size: 4096 Blocks: 8 IO Block: 4096 directoryDevice: fd01h/64769d Inode: 2 Links: 24Access: (0755/drwxr-xr-x) Uid: (0 / root) Gid: (0 / root) Access: 2018-07-24 17 purge 52.740982553 + 0800Modify: 2018-12-21 18 purl 02purl 05.258315357 + 0800Change: 2018-12-21 18purl 02Blocks 05.258315357 + 0800Birth:-link
In the output of the command ls-l, the column after the permission and before the owner is the link count. The link count refers to the number of hard links to the file. To understand hard links, let's start with links. A link is a pointer to another file. In the Linux world, there are two types of links:
a. Symbolic links (soft links)
A symbolic link is a separate file whose contents point to the linked file. To create a symbolic link, use the ln command with the-s option. When using the ln command, be sure to reference the name of the original file first, and then the name of the link you want to create.
# ln-s / home/opt/sync.sh filesync
Here filesync is the symbolic link to sync.sh. Think of it as a shortcut. Editing a filesync is like editing the original file directly. If we delete or move the original file, the link will be broken and our filesync file will no longer be available.
The ls-l command shows that the resulting file is a symbolic link. This is indicated by the letter l in the first location of the ls-l output and the arrow at the end of the list, which indicates the file to which the link points.
# ls-l filesynclrwxrwxrwx 1 root root 20 Apr 7 06:08 filesync-> / home/opt/sync.sh
When you compare symbolic links with the original file, you will find a significant difference between them.
# ls-il / home/opt/sync.sh filesync258674 lrwxrwxrwx 1 root root 20 Apr 7 06:08 filesync-> / home/opt/sync.sh517333-rw-r- 1 root root 5 Apr 7 06:09 / home/opt/sync.sh
The original file is just a file that connects directly to inode, and a symbolic link points to it. The size of the symbolic link is the number of bytes of the file name it references because there is no other information available in the symbolic link.
b. Hard link
To understand what hard links are, the key is to understand that the identity of a file is its inode number, not its name. A hard link is a name that references inode. This means that if file1 has a hard link called file2, then both files reference the same inode. So when you create a hard link for a file, all you really need to do is add a new name to the inode. To do this, use the ln command with no options.
# ls-l / home/opt/sync.sh-rw-r- 1 root root 5 Apr 7 06:09 / home/bobbin/sync.sh# ln / home/opt/sync.sh synchro
Let's compare these two files.
# ls-il / home/bobbin/sync.sh synchro517333-rw-r- 2 root root 5 Apr 7 06:09 / home/opt/sync.sh517333-rw-r- 2 root root 5 Apr 7 06:09 synchro
The interesting thing about hard links is that there is no difference between the original file and the link: they are just two names connected to the same inode.
As you must note, unlike soft links, hard links are not special files. Now, the link count is the number of hard links to the file. As a result, the link count increases after the hard link is created, as shown in the figure above. These hard links have two limitations:
Directories cannot be hard linked. Linux does not allow this to maintain the acyclic tree structure of directories. Hard links cannot be created across file systems. The two files must be on the same file system because different file systems have different separate inode tables (two files with the same inode number on different file systems are different). This is the end of the article on "how to check the inode Information of Linux". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to view the inode information of Linux". If you want to learn more knowledge, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.