{"id":3869,"date":"2011-01-06T10:09:18","date_gmt":"2011-01-06T15:09:18","guid":{"rendered":"http:\/\/g33kinfo.com\/info\/?p=3869"},"modified":"2011-01-06T10:09:18","modified_gmt":"2011-01-06T15:09:18","slug":"reduce-inode-usage","status":"publish","type":"post","link":"https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/","title":{"rendered":"Reduce inode usage"},"content":{"rendered":"<p>From <a href=\"http:\/\/sabarish4u.wordpress.com\/2009\/04\/25\/inode-usage-find-the-user-having-high-inode-usage\/\" target=\"_blank\" rel=\"noopener noreferrer\">sabarish4u.wordpress.com<\/a><\/p>\n<p>Inodes basically store information about files and folders, such as (user and group) ownership, access mode (read, write, execute permissions) and file type. On many types of file systems the number of inodes available is fixed at file system creation, limiting the maximum number of files the file system can hold. The inode number indexes a table of inodes in a known location on the device; from the inode number, the kernel can access the contents of the inode, including the location of the file allowing access to the file. A file&#8217;s inode number can be found using the ls -i command. The ls -l command displays some of the inode contents for each file. Stat will show a more complete listing of file attributes, including the inode number, number of blocks it occupies and block size.<br \/>\n<code><br \/>\n[root@host2.myserver.com] ~ >> stat .bashrc<br \/>\n  File: `.bashrc'<br \/>\n  Size: 325       \tBlocks: 8          IO Block: 4096   regular file<br \/>\nDevice: ca03h\/51715d\tInode: 293879      Links: 1<br \/>\nAccess: (0644\/-rw-r--r--)  Uid: (    0\/    root)   Gid: (    0\/    root)<br \/>\nAccess: 2011-01-06 09:39:35.000000000 -0500<br \/>\nModify: 2010-07-28 13:51:44.000000000 -0400<br \/>\nChange: 2010-08-27 16:16:18.000000000 -0400<br \/>\n<\/code><br \/>\nFile names and directory implications:<br \/>\n* Inodes do not contain file names, only file metadata.<br \/>\n* Unix directories are lists of &#8220;link&#8221; structures, each of which contains one filename and one inode number.<br \/>\n* The kernel must search a directory looking for a particular filename and then convert the filename to the correct corresponding inode number.<br \/>\n* The kernel&#8217;s in-memory representation of this data is called struct inode in Linux.<\/p>\n<p>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)<\/p>\n<p>For example If the inode usage is 100 % then we needs to find out which user\/directory has owned the maximum number of files.<br \/>\n<code><br \/>\n[root@server]# df -i<br \/>\nFilesystem            Inodes   IUsed   IFree IUse% Mounted on<br \/>\n\/dev\/vzfs             800000  800000       0  100% \/<br \/>\nsimfs                 800000  800000       0  100% \/tmp<br \/>\nsimfs                 800000  800000       0  100% \/var\/tmp<br \/>\n<\/code><br \/>\nRun the following commands<br \/>\n<code><br \/>\n[root@server ~]# repquota -a | sort -nk6 | head<\/p>\n<p>Block limits                File limits<br \/>\n*** Report for user quotas on device \/dev\/vzfs<br \/>\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014-<br \/>\nBlock grace time: 00:00; Inode grace time: 00:00<br \/>\nUser            used    soft    hard  grace    used  soft  hard  grace<br \/>\ntest1      +-   25816   25600   25600   none     663     0     0<br \/>\ntest2     \u2013       4       0       0              1     0     0<br \/>\nmail      \u2013       4       0       0              1     0     0<br \/>\n<\/code><\/p>\n<p><!--more--><\/p>\n<p>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.<br \/>\n<code><br \/>\n[root@host ~]# repquota -a | sort -nk6 | tail<br \/>\ntest10   \u2013  375660 4096000 4096000          23463     0     0<br \/>\ntest11     \u2013  482460 1024000 1024000          28043     0     0<br \/>\ntest12   \u2013  652580 1024000 1024000          29378     0     0<br \/>\ntest13  \u2013  286200 4096000 4096000          33996     0     0<br \/>\ntest14  \u2013  591400  819200  819200          39027     0     0<br \/>\ntest15    \u2014 1528680       0       0          39027     0     0<br \/>\ntest16    \u2014 1941748 8192000 8192000          46401     0     0<br \/>\ntest17    \u2013  626240       0       0          58163     0     0<br \/>\nmailnull  \u2014 1236324       0       0          89971     0     0<br \/>\nroot      \u2014 3563516       0       0         128345     0     0<\/p>\n<p>[root@host ~]#exim -bpc<br \/>\n29930<br \/>\n<\/code><br \/>\nAfter 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.<br \/>\n<code><br \/>\n[root@host ~]# cd \/home\/test17<br \/>\n[root@host \/home\/test17]# for d in *; do echo -n \u201c$d: \u201c; find $d -type f | wc -l; done ( This script will display<br \/>\nthe directory\/file and count the number of files inside that directory )<\/p>\n<p>access-logs: 0<br \/>\nbackup-5.27.2008_12-50-20_test17.tar.gz: 1<br \/>\netc: 6<br \/>\nfile.txt: 1<br \/>\nlogs: 0<br \/>\nmail: 3<br \/>\nmoodledata: 523<br \/>\npublic_ftp: 0<br \/>\npublic_html: 43469<br \/>\ntmp: 54<br \/>\nwww: 0<br \/>\n<\/code><br \/>\nHere again public_html directory contains the maximum number of files.<br \/>\n<code><br \/>\n[root@host \/home\/test17]#cd public_html<br \/>\n[root@host \/home\/test17\/public_html]# for d in *; do echo -n \u201c$d: \u201c; find $d -type f | wc -l; done | sort -nk2 | tail -5<\/p>\n<p>x_bck: 4576<br \/>\nx4: 4630<br \/>\nx5: 4680<br \/>\nx6: 4788<br \/>\nx7: 14823<br \/>\n<\/code><\/p>\n<p>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:<\/p>\n<p><code><br \/>\nfor i in `ls -1A`; do echo \"`find $i | sort -u | wc -l` $i\"; done | sort -rn | head -5<br \/>\n<\/code><\/p>\n<p>From <a href=\"http:\/\/sabarish4u.wordpress.com\/2009\/04\/25\/inode-usage-find-the-user-having-high-inode-usage\/\" target=\"_blank\" rel=\"noopener noreferrer\">sabarish4u.wordpress.com<\/a><\/p>\n<p>====================================<\/p>\n<p>To reduce the number of inodes your account uses, you should:<\/p>\n<p>1) remove all files\/folders you don&#8217;t need;<\/p>\n<p>2) check the number of cache files you have; applications such as Joomla can generate a lot of cache files; you should regularly check your cache folder and reduce the number of cached files you keep;<\/p>\n<p>3) if you have Default Address (catch-all) enabled, make sure you check the mailbox regularly and delete all mails you don&#8217;t need;<\/p>\n<p>4) check  your cPanel&#8217;s main email account regularly; the mails for it are kept in:<\/p>\n<p>         \/home\/username\/mail\/cur <\/p>\n<p>         \/home\/username\/mail\/new     <\/p>\n<p>        where username is your cPanel username. You can manually delete the messages in these folders using cPanel&#8217;s File Manager or your favorite FTP  client;<\/p>\n<p>5) you should also check your email accounts regularly and delete any spam messages from them;<\/p>\n<p>6) if you have email accounts you don&#8217;t need or use, it would be best to remove them;<\/p>\n<p>Additionally, you can delete a directory entry but, if a running process still has the file open, the inode won&#8217;t be freed. My initial thinking would be to delete all the files you can, then reboot the box to ensure no processes are left holding the files open. Lastly, you may be able to .tar.gz certain necessary but unused files or folder to temporarily reduce inode usage. <\/p>\n<p>One final thing to remember, if you are seeing a variance in the du and df command outputs on the server, the du command totals up the space of files that exist within the physical sector size (4096 bytes) of the blocks in the file system, while df shows all of the (4096 bytes) blocks available in the file system. <\/p>\n<p>This is because the maximum number of inodes (and hence the maximum number of files and directories) is set when the file system is created. If V is the volume size in bytes, then the default number of inodes is given by V\/213 (or the number of blocks, whichever is less), and the minimum by V\/223. The default was deemed sufficient for most applications. The max number of subdirectories in one directory is fixed to 32000.<\/p>\n<p>There are several ways to specify more inodes at filesystem creation time:<br \/>\n<code><br \/>\n\tmke2fs -i 4096 <dev>\t# one inode per 4kB instead of default 8kB<br \/>\n\tmke2fs -N 4000000 <\/dev><dev>\t# create at least 4M inodes<br \/>\n\tmke2fs -T news <\/dev><dev>\t# same as using -i 4096<br \/>\n<\/dev><\/code><br \/>\nIf your average filesize is much less than 4kB, you could also use smaller disk blocks to store them more compactly:<br \/>\n<code><br \/>\n\tmke2fs -b 2048 -i 2048 <dev>\t# average filesize < = 2kB\n\tmke2fs -b 1024 -i 1024 <dev>\t# average filesize < = 1kB\n<\/code><br \/>\nNote: that with so many small files in such a large disk, you may have performance problems if there are lots of files in a single directory.<\/dev><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>From sabarish4u.wordpress.com Inodes basically store information about files and folders, such as (user and group) ownership, access mode (read, write, execute permissions) and file type. On many types of file systems the number of inodes available is fixed at file system creation, limiting the maximum number of files the file system can hold. The inode&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-3869","post","type-post","status-publish","format-standard","hentry","category-info"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Reduce inode usage - Linux Shtuff<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Reduce inode usage - Linux Shtuff\" \/>\n<meta property=\"og:description\" content=\"From sabarish4u.wordpress.com Inodes basically store information about files and folders, such as (user and group) ownership, access mode (read, write, execute permissions) and file type. On many types of file systems the number of inodes available is fixed at file system creation, limiting the maximum number of files the file system can hold. The inode... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux Shtuff\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:author\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:published_time\" content=\"2011-01-06T15:09:18+00:00\" \/>\n<meta name=\"author\" content=\"g33kadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/drsinger1111\" \/>\n<meta name=\"twitter:site\" content=\"@drsinger1111\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/reduce-inode-usage\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/reduce-inode-usage\\\/\"},\"author\":{\"name\":\"g33kadmin\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"headline\":\"Reduce inode usage\",\"datePublished\":\"2011-01-06T15:09:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/reduce-inode-usage\\\/\"},\"wordCount\":847,\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"articleSection\":[\"General Info\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/reduce-inode-usage\\\/\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/reduce-inode-usage\\\/\",\"name\":\"Reduce inode usage - Linux Shtuff\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\"},\"datePublished\":\"2011-01-06T15:09:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/reduce-inode-usage\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/reduce-inode-usage\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/reduce-inode-usage\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Reduce inode usage\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\",\"name\":\"Linux Shtuff\",\"description\":\"Because I have CRS Syndrome...\",\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\",\"name\":\"g33kadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"contentUrl\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"width\":512,\"height\":512,\"caption\":\"g33kadmin\"},\"logo\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\"},\"description\":\"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\\\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....\",\"sameAs\":[\"https:\\\/\\\/thelinuxreport.com\",\"https:\\\/\\\/fb.me\\\/g33kinf0\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/drsinger1111\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Reduce inode usage - Linux Shtuff","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/","og_locale":"en_US","og_type":"article","og_title":"Reduce inode usage - Linux Shtuff","og_description":"From sabarish4u.wordpress.com Inodes basically store information about files and folders, such as (user and group) ownership, access mode (read, write, execute permissions) and file type. On many types of file systems the number of inodes available is fixed at file system creation, limiting the maximum number of files the file system can hold. The inode... Read More","og_url":"https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/","og_site_name":"Linux Shtuff","article_publisher":"https:\/\/fb.me\/g33kinf0","article_author":"https:\/\/fb.me\/g33kinf0","article_published_time":"2011-01-06T15:09:18+00:00","author":"g33kadmin","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/drsinger1111","twitter_site":"@drsinger1111","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/#article","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/"},"author":{"name":"g33kadmin","@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"headline":"Reduce inode usage","datePublished":"2011-01-06T15:09:18+00:00","mainEntityOfPage":{"@id":"https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/"},"wordCount":847,"publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"articleSection":["General Info"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/","url":"https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/","name":"Reduce inode usage - Linux Shtuff","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/#website"},"datePublished":"2011-01-06T15:09:18+00:00","breadcrumb":{"@id":"https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/g33kinfo.com\/info\/reduce-inode-usage\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/g33kinfo.com\/info\/"},{"@type":"ListItem","position":2,"name":"Reduce inode usage"}]},{"@type":"WebSite","@id":"https:\/\/g33kinfo.com\/info\/#website","url":"https:\/\/g33kinfo.com\/info\/","name":"Linux Shtuff","description":"Because I have CRS Syndrome...","publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/g33kinfo.com\/info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547","name":"g33kadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","url":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","contentUrl":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","width":512,"height":512,"caption":"g33kadmin"},"logo":{"@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif"},"description":"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....","sameAs":["https:\/\/thelinuxreport.com","https:\/\/fb.me\/g33kinf0","https:\/\/x.com\/https:\/\/twitter.com\/drsinger1111"]}]}},"_links":{"self":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/3869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/comments?post=3869"}],"version-history":[{"count":0,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/3869\/revisions"}],"wp:attachment":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/media?parent=3869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/categories?post=3869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/tags?post=3869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}