-->

Previous | Table of Contents | Next

Page 296

The df (free disk space) command will gather and summarize some important statistics about all currently mounted filesystems. The df command is easy to use, for example:


# df

Filesystem         1024-blocks  Used Available Capacity Mounted on

/dev/hda3             497699  443871    28124     94%   /

/dev/hda1             509856  469632    40224     92%   /mnt/dos

/dev/hdc1               3868    2596     1272     67%   /mnt/flash

/dev/hdb              644324  644324        0    100%   /mnt/cdrom

This output shows four different filesystems on three different devices mounted under Linux. The first is the root partition at the / directory on /dev/hda3; the second is a DOS partition under /mnt/dos on /dev/hda1; the third is a flashcard under /mnt/flash on /dev/hdc1; and the fourth is a CD-ROM, mounted under /mnt/cdrom on /dev/dev/hdb. The df command also lists the size of the storage device, how much has been used, how much is available, and the current capacity of the device. Notice that the CD-ROM has no space left. This is because it is mounted read-only, meaning you can't save or delete files on this device. The command shown in the next example will let you know.

One handy way to find out about the different filesystems you have mounted is to use the mount command. This command is usually used during startup, and by the root operator to mount and unmount filesystems, but you can use mount to show what type of filesystems are in use, and how the filesystems are mounted, for example:


# mount

/dev/hda3 on / type ext2 (rw)

/dev/hda1 on /mnt/dos type msdos (rw)

none on /proc type proc (rw)

/dev/hdc1 on /mnt/flash type msdos (rw)

/dev/hdb on /mnt/cdrom type iso9660 (ro)

This shows that your root partition, on the / directory, is a Linux ext2 filesystem mounted read-write, whereas /mnt/dos and /mnt/flash contain DOS partitions, also read-write. (The /proc filesystem is a special directory Linux uses for process reporting, such as running applications, system state, and so on.) Finally, mount reports that your CD-ROM is mounted as a read-only iso9660 filesystem.

You can use this information from mount to get specific information with the df command, by using the df command's -t, or filesystem, option, as follows:


# df -t ext2

Filesystem         1024-blocks  Used Available Capacity Mounted on

/dev/hda3             497699  443873    28122     94%   /

This tells df to just show information about any mounted Linux filesystems. You can get a list of valid filesystems to specify with the df command by looking at the mount manual page. The mount command is covered in more detail in Hour 21, "Handling Files." You can see

Page 297

that by using the df and mount command, you can get reports on the type of mounted devices, how the devices are mounted, and how much room you have left on each.

Getting Filesystem Disk Usage with the du Command

The du (disk usage) command conveniently summarizes how your disk is being used, by reporting the amount of space required by each directory or specified path. Although the du command has more than 20 command-line options, this section presents some of the common ones, and leaves it up to you to experiment. You can use the du command by itself, or specify a directory or path, for example:


# du

904     ./book

12080   ./mail

1       ./.tin/.mailidx

1       ./.tin/.index

10      ./.tin

...

589     ./News

9       ./.index

7       ./.procmail

5       ./.ncftp

418     ./reading

778     ./documents

27199   .

This report (for brevity, not all the directories are listed) shows the contents of a home directory, with a total for 27,199 1-kilobyte blocks. If you find this hard to understand, you can have du report the size in bytes, for example:


# du -b

897606  ./book

12294410        ./mail

1024    ./.tin/.mailidx

1024    ./.tin/.index

9382    ./.tin

561715  ./News

4033    ./.index

4139    ./.procmail

2791    ./.ncftp

424037  ./reading

784216  ./documents

26785752        .

If this is too much information for you, then you can use the --summarize option to get the total in either kilobytes or bytes, as follows:


# du -b --summarize

26786903        .

The du command can also help you keep track of directories which, unattended, sometimes grow out of control or use a lot of disk space. If you specify a path, du will report on the

Page 298

different size of the directories, pinpointing any that may contain too much information, for example:


# du --summarize -b /var/* | sort -nr

6474535 /var/lib

2336494 /var/log

868163  /var/catman

76362   /var/spool

14591   /var/dt

2385    /var/run

2048    /var/lock

2048    /var/local

1024    /var/tmp

1024    /var/preserve

1024    /var/nis

Here I've combined the du command, which has been instructed to summarize the number of bytes in each directory, with the sort command, which has been set to use a numerical sort in reverse order. This one-liner, which uses pipes (discussed in Hour 6, "Using the Shell"), will automatically print the largest directories at the top of the output list. You can see that the /var/log directory is getting pretty big. The /var/lib directory will be large because it contains the rpm databases (rpm is discussed in Hour 22, "Red Hat Tools").

Although the du command does not, like the df command, have a -t option to specify which filesystem to report on, you can use the -x option to exclude other filesystems. Or, you can have du report on other filesystems by specifying a usage report at the mount point. For example, du will merrily chug along and summarize how much room your Windows directories take up:


# du -b --summarize /mnt/dos/* | sort -nr

129486405       /mnt/dos/windows

23929345        /mnt/dos/msoffice

20811654        /mnt/dos/photoenf

7744046 /mnt/dos/tranxit

6828902 /mnt/dos/org2

6647520 /mnt/dos/laplink

5556496 /mnt/dos/acrobat3

4041127 /mnt/dos/pcdr

3753962 /mnt/dos/psp

3603469 /mnt/dos/insync

3176769 /mnt/dos/antvirus

2669335 /mnt/dos/airlite

2408920 /mnt/dos/winfax

...

This (shortened) report shows that next to the operating system, the largest space is taken up by certain applications. This information can be helpful in making a decision on what applications to uninstall if you need more disk space.

Checking Symbolic Links with the stat Command

Previous | Table of Contents | Next