2018 Aug 04 By itops_admin 0 comment

In my years in IT I’ve handled a lot of storage (proprietary and open source solutions).
But one of the main issues that I had (beside design of large storage and backup) is the rouge user/script/program – sometime one of them will act up and fill the storage with large amount of files or one massive file (for example a big log file).

From time to time someone comes to me and say “Well my script isn’t working” – one of the first things I do is running “quota -u <USERNAME>” and 90% of the time We both see that the user filled his size or inodes quota and hist script fail.
From time to time I collected a lot of scripts and one liners to help me search for the problematic dir/file that contain the issue.

Here are some nice one-liners that can help you find the culprit:

Beware! Using some of this one liners on a directory that have under it local or NAS mount (example: nfs) won’t yield the correct result!
Make sure you run this lines where the you only scan one “device” (local mount, nfs mount etc…) at a time!

  •  Find the largest file amount in current directory (it will only show the current level of directories)
    for x in .*/ */; do if [ "$x" != './' ] && [ "$x" != '../' ]; then x=${x#*\'}; x=${x%\'*}; y=`find "$x"|wc -l`; echo -e "$y\t $x";fi; done|sort -k1 -h
  •  Find big directory under your current location (You will need to keep following the path deeper until you find the problematic directory)
    du --block-size=1G --max-depth=2|sort -rh|head
  • Find large files:
    (Replace <path/to/dir/> with the path to the directory you want to search in)

    find </path/to/dir/> -printf '%s %p\n'| sort -nr | head -10
  • Check your current location device free space (this work even if there is another mount under it):
    df -h .



Leave a Reply

Your email address will not be published. Required fields are marked *