Skip to content

By Administrator in All, Linux administration

The command below can be very useful in identifying which folders on your system are containing the largest numbers of files (inodes). It frequently happens that a caching or logging component of a web application goes berserk and starts generating an enormous amount of files in a certain subfolder. Such an event might be trouble if the system imposes inode usage limitations as many web hosting providers do. If we are lucky, the folder would be called “cache” but in the less fortunate cases, the following sequence of commands can come in handy:

ls -la | grep drwx | awk '{for (i=1; i<=NF-7; i++) $i = $(i+7); NF-=7; print}'
| grep -v '^\.\.$' | while read i; do echo `find "$i"
| wc -l` - $i; done | sort -n

When you execute this line, it will print a list of all subfolders of the current folder and the number of files each one of them contains. You can then cd to the subfolders that contain most files and execute the line again in case the excessive files are in a sub-subfolder.

Below is a portion of the output the above command generated for my home folder:

115 - firefox
126 - .gftp
131 - .thunderbird
152 - .openoffice.org
171 - .Skype
173 - .java
184 - .opera
217 - .cache
233 - .local
272 - .google
280 - .config
438 - Downloads
444 - .compiz
488 - .gconf
1617 - .mozilla
1690 - .googleearth
13407 - Desktop
14916 - .thumbnails
35418 - .

I can now run the command again and find out which folders on my Desktop contain the most of the 13407 files.

Tags: , , ,

Comment Feed

No Responses (yet)



Some HTML is OK

or, reply to this post via trackback.