files/partitions question

Rick Stevens rstevens at vitalstream.com
Tue Sep 27 18:05:07 UTC 2005


On Tue, 2005-09-27 at 10:01 -0700, Mark Knecht wrote:
> Hi,
>    Probably a simple question for some wily old-timer. ;-)
> 
>    I have a system in which the root partition seems to be getting a
> bit full. It got up to about 96% full and I've cleared some things
> out, but now I want to understand what's still there and using up 8GB.
> 
> dragonfly / # df
> Filesystem           1K-blocks      Used Available Use% Mounted on
> /dev/hda8              9621848   8121392   1011680  89% /
> udev                    249524       360    249164   1% /dev
> /dev/hda2             50394996  47146084    688956  99% /Musiclib
> /dev/hda3             30233928   1792032  26906084   7% /home
> /dev/hda9              9621848   2726716   6406356  30% /CODE
> /dev/hda10             2893628    405328   2341308  15% /var
> none                    249524         0    249524   0% /dev/shm
> myth14:/video        225373664 110171552 103753792  52% /video
> dragonfly / #
> 
>   From the du man page it seems that I should be able to run du -x and
> only get the usage of the specific drive and not the partitions that
> are on other drives, so I try it:
> 
> dragonfly / # du -x /
> 16      /lost+found
> 4       /boot
> 5392    /bin
> 0       /dev
> <SNIP>
> 7964    /root
> 4       /Froot
> 12      /Musiclib
> 8       /service
> 8       /video
> 4       /video1
> 3526456 /
> dragonfly / #
> 
>    Indeed, this command does not appear to traverse other drives. I do
> not see /var, /home, etc., but when it's finished it says that only
> 3.5 GB are used while the df command tells me 8.1GB is used. Which is
> correct?

The most common cause of this is having a process running that's opened
a big file for appending, but hasn't actually used any space yet.  "du"
tells you what's actually being used.  "df" will tell you what's
_reserved_ and MAY be used.

Verify you don't have a process open somewhere that's holding an open
file.  If you've purged a bunch of stuff on the drive, then the free
space may not show up in "df" until you reboot or close whatever
application has a file open in that directory.

>    As a bonus question, if I know the name of a file and want to know
> what drive it's on, how can I do that at the command line? I'd most
> like a command that reports back file so-and-so resides on /dev/hda11
> if possible.

Hooo, boy!  The vast majority of programs that do that use either fixed
paths (e.g. "whereis") or use the $PATH environment ("which").  If you
just have a filename, you'd need to use "find" to locate the file, then
pass the directory name to a pattern matcher and print the appropriate
stuff by examining /etc/mtab.  There's no simple way to do it.  Here's
a shell script that can do it, but it's bloody nasty!

------------------------ Cut Here -------------------------------------
#!/bin/bash
RES=`find / -noleaf -name $1 -print`
if [ $? -ne 0 ]; then
    echo No such file found
    exit 1
fi
for LINE in $RES; do
    XLINE=$LINE
    RC=1
    while [ $RC -ne 0 ]; do
        XPATH=`dirname $XLINE`
        XX=`grep $XPATH /etc/mtab`
        RC=$?
        if [ $RC -ne 0 ]; then
            XLINE=$XPATH
        else
            echo -n "$LINE is on "
            echo $XX | awk '{print $1;}'
            break;
        fi
    done
done
------------------------ Cut Here -------------------------------------

If saved as "/usr/local/bin/whichdrive", then

	/usr/local/bin/whichdrive filename

should reveal it.  Remember, "find" can take a LONG time.  You could
modify the script to use slocate and a restrictive regular expression
if you wish.  I leave that as an exercise for the reader (meaning "I'm
too d at mned lazy to write it")  :-)

----------------------------------------------------------------------
- Rick Stevens, Senior Systems Engineer     rstevens at vitalstream.com -
- VitalStream, Inc.                       http://www.vitalstream.com -
-                                                                    -
-   "Do you suffer from long-term memory loss?"  "I don't remember"  -
-                            -- Chumbawumba, "Amnesia" (TubThumping) -
----------------------------------------------------------------------




More information about the Redhat-install-list mailing list