We can find the inode usage (Number of files) owned by each user/directory, especially useful in VPS. Each VPS will have inode limits (the maximum number of files that can be created in that VPS)

For example If the inode usage is 100 % then we needs to find out which user/directory has owned the maximum number of files.

[[email protected]]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/vzfs 800000 800000 0 100% /
simfs 800000 800000 0 100% /tmp
simfs 800000 800000 0 100% /var/tmp

Run the following commands

[[email protected] ~]# repquota -a | sort -nk6 | head
Block limits File limits
*** Report for user quotas on device /dev/vzfs
———————————————————————-
Block grace time: 00:00; Inode grace time: 00:00
User used soft hard grace used soft hard grace
test1 +- 25816 25600 25600 none 663 0 0
test2 — 4 0 0 1 0 0
mail — 4 0 0 1 0 0

In my case the user mailnull (the system user used by exim to store queued emails) owned maximum number of files as there were around 30000 emails in the mail queue. From the command output shown below the mailnull user has the inode usage of 89971.

[[email protected] ~]# repquota -a | sort -nk6 | tail
test10 — 375660 4096000 4096000 23463 0 0
test11 — 482460 1024000 1024000 28043 0 0
test12 — 652580 1024000 1024000 29378 0 0
test13 — 286200 4096000 4096000 33996 0 0
test14 — 591400 819200 819200 39027 0 0
test15 — 1528680 0 0 39027 0 0
test16 — 1941748 8192000 8192000 46401 0 0
test17 — 626240 0 0 58163 0 0
mailnull — 1236324 0 0 89971 0 0
root — 3563516 0 0 128345 0 0
[[email protected] ~]#exim -bpc
29930

After mailnull the next user who has owned maximum number of files is test17 (58163). Now need to find out which directory contains maximum number of files.

[[email protected] ~]# cd /home/test17
[[email protected] /home/test17]# for d in *; do echo -n “$d: “; find $d -type f | wc -l; done

( This script will display
the directory/file and count the number of files inside that directory )

access-logs: 0
backup-5.27.2008_12-50-20_test17.tar.gz: 1
etc: 6
file.txt: 1
logs: 0
mail: 3
moodledata: 523
public_ftp: 0
public_html: 43469
tmp: 54
www: 0

Here again public_html directory contains the maximum number of files.

[[email protected] /home/test17]#cd public_html
[[email protected] /home/test17/public_html]# for d in *; do echo -n “$d: “; find $d -type f | wc -l; done | sort -nk2 | tail -5
x_bck: 4576
x4: 4630
x5: 4680
x6: 4788
x7: 14823

Finally the directory x7 contains the maximum number of files (inodes).

Similarly by using this method we can find out which user/directory owns the maximum number of files in any linux server.

This command might be helpful to you in finding the folder using a great part of the inodes. It outputs the top 5 file system objects utilizing the most inodes in the current folder:

for i in `ls -1A`; do echo "`find $i | sort -u | wc -l` $i"; done | sort -rn | head -5
Previous ArticleNext Article

Leave a Reply

Your email address will not be published.