Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003

    Unanswered: script to find largest files in directory

    The below will show that I am obviously new to unix system/space management.

    server stats:
    SunOS sunprod1 5.8 Generic_108528-17 sun4u sparc SUNW,Ultra-80
    We ran into a problem last night on our production server.
    We kept getting a 'disk full' error when we attempted to build the new application files to a specific directory.

    A 'df' showed that there was block space available. However, a 'df -k' showed capacity was full (100%) on a few filesystems.

    It took us forever to find the files that were HUGE in size (ended up being log-files for Apache), but buried deep withing those directory paths.

    I was wondering if anyone had a script to find files with a directory and through the sub-directory path that are of a large size or over a specified size so that I can avoid these problems ahead of time in the future.

    Also, is there any way to allocate space from one filesystem to another?

    Thanks for your time.
    - The_Duck
    you can lead someone to something but they will never learn anything ...

  2. #2
    Join Date
    Mar 2002
    Reading, UK
    Try using du to find which directories are taking up the most space. Doing du at the top level will list the size of every directory (but it does include subdirectories in the size of the current dir). You can also pipe into sort to sort the output so the largest end up at the end. Also du -s will list only the size of the directories in your current directory.


  3. #3
    Join Date
    Jun 2003
    West Palm Beach, FL


    You could try something like this:

    # With df -k find the directory that is full:
    dir=$(df -k|sort +4n|tail -1|awk '{print $6;}')
    # set the maximum file size:
    export MAXSZ=1024000
    #lookup all files > MAXSZ
    find $dir -ls |awk '{if (int($7) >= int(sz)) printf "%15s %s\n",$7,$11;}' sz=$MAXSZ | sort -r
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts