Managing Linux Disk Space
In the process of installing programs, downloading/ripping movies, and doing whatever else we do with our Linux systems, managing disk space becomes crucial. Here’s some helpful hints on how to measure/manage disk space under Linux.
This command meaning ‘disk free’ will tell you how much of each partition you still have available to you. It handles all mounted filesystems including mounted samba shares. Due to it’s design as a tool to measure available disk space, it won’t tell you anything about your disk drives.
# dfthis outputs a display of the total partition usage
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda5 13100844 9906872 2528484 80% /
/dev/hda6 5463156 3245016 1940620 63% /mnt/v_drive
/dev/hda7 451564 68 451496 1% /tmp
/dev/hda8 6103648 3706120 2087476 64% /mnt/z_drive
/dev/hda9 24527248 16671184 7856064 68% /mnt/x_drive
/dev/hda1 8361512 5603640 2757872 68% /mnt/winxp
none 451564 0 451564 0% /dev/shm
//192.168.0.7/x 72595456 72282112 313344 100% /mnt/kingdom/x
//192.168.0.7/m 75335680 74567680 768000 99% /mnt/kingdom/m
//192.168.0.7/temp 75335680 74567680 768000 99% /mnt/kingdom/temp
# df -hthis outputs the same thing in a human-readable format
/dev/hda5 13G 9.5G 2.5G 80% /
/dev/hda6 5.3G 3.1G 1.9G 63% /mnt/v_drive
/dev/hda7 441M 68K 441M 1% /tmp
/dev/hda8 5.9G 3.6G 2.0G 64% /mnt/z_drive
/dev/hda9 24G 16G 7.5G 68% /mnt/x_drive
/dev/hda1 8.0G 5.4G 2.7G 68% /mnt/winxp
# df -kif you want to see things in Kilobytes
/dev/hda5 13100844 9906884 2528472 80% /
/dev/hda6 5463156 3247992 1937644 63% /mnt/v_drive
/dev/hda7 451564 68 451496 1% /tmp
/dev/hda8 6103648 3706120 2087476 64% /mnt/z_drive
/dev/hda9 24527248 16671184 7856064 68% /mnt/x_drive
/dev/hda1 8361512 5603640 2757872 68% /mnt/winxp
‘disk usage’ measures individual sections of the filesystem rather than whole partitions. You can pass it a directory name or nothing at all to let it calculate the current directory.
# duthis lists, recursively, the size of all directories beneath the current directory.
68 ./.kde3.4/share/config/session
8 ./.kde3.4/share/config/kresources/contact
4 ./.kde3.4/share/config/kresources/calendar
4 ./.kde3.4/share/config/kresources/konnector
4 ./.kde3.4/share/config/kresources/notes
24 ./.kde3.4/share/config/kresources
12 ./.kde3.4/share/config/colors
648 ./.kde3.4/share/config
32 ./.kde3.4/share/apps/kconf_update
4 ./.kde3.4/share/apps/kopete
4 ./.kde3.4/share/apps/remoteview
8 ./.kde3.4/share/apps/nsplugins
... etc ...
# du /home/danger -hthe same thing as the above but for a certain directory and with better units for filesizes (KB, MB, GB).
68K /home/danger/.kde3.4/share/config/session
8.0K /home/danger/.kde3.4/share/config/kresources/contact
4.0K /home/danger/.kde3.4/share/config/kresources/calendar
4.0K /home/danger/.kde3.4/share/config/kresources/konnector
4.0K /home/danger/.kde3.4/share/config/kresources/notes
24K /home/danger/.kde3.4/share/config/kresources
12K /home/danger/.kde3.4/share/config/colors
648K /home/danger/.kde3.4/share/config
32K /home/danger/.kde3.4/share/apps/kconf_update
4.0K /home/danger/.kde3.4/share/apps/kopete
..... etc ......
# du -shcalculates the size of the current directory’s total contents (and prints it in ‘h’ format).
204M
As I learn more about terminals and bash commands I’m finding some excellent shortcuts for common operations. They’re nothing secret, they’re just new to me.
# df -h | grep /dev/hda5 show just one partition/device in the list. You can replace the ‘/dev/hda5′ with any other text that you’re looking for.
/dev/hda5 13G 9.5G 2.5G 80% /
# df -h | grep /dev/hda5 | cut -c 41-43 same as above, but it further narrows down the output to include only the 41st through the 43rd characters of the list - which is the part that shows percentages.
80%
# du –exclude=logthis will ‘du’ all the files except ones that match the pattern in the exclude clause. In this case, any file that contains the three-letter combo ‘log’ will not be counted in the results. Can be really handy also for ignoring movies, music, etc.
If any of you have something to add, please chime in - I’d be happy to add your comments as an update to this post (as well as try out the new comment display I’ve got - they show up opposite the post on the right side of the page).