How To Count Inode Usage In Linux?

नॉलेजबेस लेख और समाचार

Views
658
Useful
0
By
Admin

How To Count Inode Usage In Linux?

This Article written by  Magesh Maruthamuthua at 2daygeek.com

As you know, everything is a file in Linux.

Each and every files (It includes all kind of files) and folders/directory called inode.

Each file or directory adds 1 to the inode count.

In this article, we will show you, how to check inode and its count.

Also, we will tell you, how to count for specific user.

What Is Inode?

The inode stands for index node or index number is a data structure in a Linux file system that stores information about a file and directory.

File systems in general have two parts, those are metadata and actual data.

Each file has an inode containing metadata about the file. Each file in a filesystem has a unique inode number. Inode numbers are guaranteed to be unique only within a filesystem.

You may 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 In Linux?

Use the ls command with -i option to view the file inode number. The inode number of the file will be shown in the first field of the output.

# ls -li 2daygeek.txt

1740436 -rw-r--r-- 1 daygeek daygeek 211 Feb 10 08:03 2daygeek.txt

How To Search A File Using Inode Number In Linux?

You can able to find the files using inode number in Linux. To do so, use the following format.

# find /home/daygeek/ -inum 1740436

/home/daygeek/2daygeek.txt

How To Check Inode Utilization On The File System In Linux?

If you would like to check inode utilization on the file system then run the following command.

# df -i
Filesystem       Inodes   IUsed    IFree IUse% Mounted on
/dev/vda1      13640832 1487624 12153208   11% /
devtmpfs         232604     326   232278    1% /dev
tmpfs            235277       1   235276    1% /dev/shm
tmpfs            235277     555   234722    1% /run
tmpfs            235277      16   235261    1% /sys/fs/cgroup
/dev/loop0       146592     139   146453    1% /tmp
tmpfs            235277       1   235276    1% /run/user/0

How To Count Inode Usage In Linux?

If you would like to count inode utilization in the current directory, use the following command. This will print the output without grand total.

# pwd
/home/daygeek

# find . -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn
  43113 ./.cache
  16491 ./.rustup
   4057 ./.mozilla
   3257 ./Documents
   3054 ./.local
   1869 ./.config
   1567 ./.npm
   1551 ./Videos
    964 ./.cargo
    249 ./Pictures
    185 ./Downloads
    177 ./.bundle
    158 ./yay
    155 ./Desktop
    145 ./snap
    139 ./batstat

How To Count Inode Usage In Linux 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.

# echo "Detailed Inode usage for: $(pwd)" ; for d in find -maxdepth 1 -type d |cut -d\/ -f2 |grep -xv . |sort; do c=$(find $d |wc -l) ; printf "$c\t\t- $d\n" ; done ; printf "Total: \t\t$(find $(pwd) | wc -l)\n"

Detailed Inode usage for: /home/daygeek
11  - 2g
46  - bash-insulter
140  - batstat
96  - betty
178  - .bundle
43114  - .cache
965  - .cargo
1870  - .config
156  - Desktop
3258  - Documents
186  - Downloads
60  - drivesync
3055  - .local
4058  - .mozilla
1568  - .npm
250  - Pictures
16492  - .rustup
146  - snap
64  - ssh-audit
1552  - Videos
159  - yay

Total:   77682

How To Check Inode Changes With Copy And Move?

Inode values doesn’t get change/modify when you perform the file move with in the file system. See the results below.

# ls -li /home/daygeek/2daygeek.txt 
1740436 -rw-r--r-- 1 daygeek daygeek 211 Feb 10 08:03 /home/daygeek/2daygeek.txt

# mv /home/daygeek/2daygeek.txt /home/daygeek/Downloads/

# ls -li /home/daygeek/Downloads/2daygeek.txt
1740436 -rw-r--r-- 1 daygeek daygeek 211 Feb 10 08:03 /home/daygeek/Downloads/2daygeek.txt

Inode values get changed/modified when you perform the file copy in Linux. See the results below.

# ls -li /home/daygeek/Downloads/2daygeek.txt
1740436 -rw-r--r-- 1 daygeek daygeek 211 Feb 10 08:03 /home/daygeek/Downloads/2daygeek.txt

# cp /home/daygeek/Downloads/2daygeek.txt /home/daygeek/Downloads/2daygeek-new.txt

# ls -li /home/daygeek/Downloads/2daygeek-new.txt
1743316 -rw-r--r-- 1 daygeek daygeek 211 Apr  5 09:51 /home/daygeek/Downloads/2daygeek-new.txt

How To Reduce The Inode Usage In Linux?

The only option is to delete the unused files to reduce the inode usage in Linux.

Bonus Tips For Website Owners

Most of the hosting providers were offering the Shared UNLIMITED hosting.

Is it true? No it’s not true because there is no UNLIMITED hard disk then how can its possible?

Every web hosters were provide some Terms & condition for INODE limits so, have a look on it before you buy the hosting.

If the shared hosting is not suitable for you then try Virtual Private Server (VPS) or Dedicated Server (DS) because there is no limit for inode usage.

इस पोस्ट पर साझा करें

संबंधित टैग