How to count Inode usage in Linux?
Each and every file & folder is considered as inode, which includes normal file, directory, link file, block file, device file, etc.
Each file or directory adds 1 to the inode count.
In this article, we will show you how to check the inode number of files and how to calculate the inode usage for a particular user.
What is Inode?
The inode stands for index node or index number. It is a data structure in a Linux file system that stores information about a file and directory.
File system generally consist of two parts, which are metadata and actual data.
Every file has a unique inode number that contains metadata about the file and the inode numbers will be unique only within the same file system.
You might get the following error when inode is full on the file system:
No space left on device or running out of Inodes.
Inode stores the following information about a file.
- Size of the file.
- Device ID
- User ID (UID)
- Group ID (GID)
- Information about permissions (read, write, execute, etc)
- File access privileges (owner, group and others)
- Time stamps information such as file access, file modification, file deletion and inode number change.
- Information about soft links and hard links
- Location of the file on the file system
How to check Inode number of the file
Use ls command with -i option to view the inode number of the file, which can be found in the first field of the output.
Searching a file using Inode number
Normally, we use a file name or other parameters to find a file, but this can be done using the inode number as well. Use the following format to search a file using its inode number.
Checking Inode usage of file system
Use the following command to check the inode usage of active file system on your system.
How to count Inode usage
If you would like to count inode utilization in the current directory, use the following command. This will print the output without grand total.
Counting Inode usage with grand total
If you would like to count inode utilization in the current directory, use the following command. This will print the output with grand total.
Checking Inode changes with ‘mv’ command
Inode values aren’t changed or modified when the file is moved within the file system. See the output below:
Checking Inode changes with ‘copy’ command
Inode values get changed or modified when the file is copied to another location. See the results below (a copy of the file is created in another location with a different name):
How to reduce Inode usage
The only option is to delete the unused files to reduce inode usage in Linux.
Bonus Tips for website owners
Most of the hosting providers claim to offer a Shared UNLIMITED hosting.
Is it true? No, it’s not! Because there is no way to offer such a service. Every web hoster have some Terms & Condition for INODE limits, so have a look at it before you buy their hosting.
If shared hosting is not suitable for you then try Virtual Private Server (VPS) or Dedicated Server (DS), because these are dedicated environment, which allows you to use complete storage and there is no restriction for inode usage as well.
Как посмотреть количество inodes в linux
Last updated on: 2021-03-19
Authored by: Miguel Salgado
This article provides an overview of the concept of inode and some helpful commands.
What is an inode?
Linux® must allocate an index node (inode) for every file and directory in the filesystem. Inodes do not store actual data. Instead, they store the metadata where you can find the storage blocks of each file’s data.
Metadata in an inode
The following metadata exists in an inode:
- File type
- Permissions
- Owner ID
- Group ID
- Size of file
- Time last accessed
- Time last modified
- Soft/Hard Links
- Access Control List (ACLs)
Check the inode number in a specific file
There are different ways to check the inode number. The following example shows the creation of a file named mytestfile. The command stat displays the file statistics, including the unique inode number:
You can also check the inode number of mytestfile by listing the contents of the directory. You can run a combination of commands in the directory by using ls or grep , as shown in the following examples:
Check the inode usage on filesystems
The following example checks the inodes on all the mounted filesystems, focusing on /dev/xvda1, which has a maximum inode allocation of 1,310,720:
Adding the flag -h to the preceding df command does not give you an exact number, but it provides a more readable output:
Count inodes under a certain directory
To check the number of inodes in a specific directory, run the following command:
The following example checks the file count in the /root directory.
In this case, it shows 11 files created under /root.
What happens to the inode assigned when moving or copying a file?
When you copy a file, Linux assigns a different inode to the new file, as shown in the following example:
Things are different when moving a file. As long as the file does not change filesystems, the inode remains the same:
The following example moves file1 from /dev/xvda1 to the /dev/xvdb1 filesystem:
When the system moved the file to another filesystem, it assigned a different inode.
Best practices to keep the inode usage low
You should check your inode usage because excessive usage can lead to issues when creating newer files. Perform the following steps to keep your usage low:
- Delete unnecessary files and directories.
- Delete cache files.
- Delete old email files.
- Delete temporary files.
What could happen if you never attend to inodes?
Even though the server has free disk space, the server can run out of inodes, which can result in the following consequences when the server does not have enough inodes when creating more files:
- You might lose data.
- The applications might crash.
- The server might restart.
- Processes might not restart.
- Scheduled tasks might not run.
Share this information:
©2020 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License
Sorry, you have been blocked
This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.
What can I do to resolve this?
You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.
Cloudflare Ray ID: 7d99dce06e882de9 • Your IP: Click to reveal 88.135.219.175 • Performance & security by Cloudflare
How to Get Total Inodes of Root Partition
On Linux and other Unix-like operating systems, an inode stores information that describes a file or directory (also a file – because everything is a file in Unix) except its name and content or its actual data. Therefore, each file is indexed by an inode which is metadata about the file.
An inode contains information such as the physical location of the file, the size of the file, the file’s owner and group, the file’s access permissions (read, write and execute), timestamps, as well as a counter indicating the number of hard links pointing to the file.
Why is it important to keep an eye on inodes?
One of the possible ways in which a filesystem can run out of space is when all the inodes are used up. This can happen even when there is enough free space on disk; consumption of all inodes in the filesystem can block the creation of new files. Besides, it can result in a sudden stop of the system.
To get the number of inodes of files in a directory, for example, the root directory, open a terminal window and run the following ls command, where the -l option means long listing format, -a means all files and -i mean to print the index number of each file.
To get the total number of inodes in the root directory, run the following du command.
To list statistics about inode usage (amount available, amount used and amount free and use percentage) in the root partition, use the df commands as follows (the -h flag allows for showing information in a human-readable format).