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.

df

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

du

‘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

Tricky 1337 stuff

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).

Linux Distros:





Subscribe in NewsGator Online



Distro Reviews:

Portage makes KDE go zoom

Last week I had some undiagnosable problem at bootup and I decided to just backup my home directory, /etc and some other key files and reinstall Gentoo from scratch (stage 1). It turned out to take longer than I remembered, but it has proven to be well worth it.
Having run Gentoo before (for a […]

Debian Sarge Released

Debian 3.1 has finally been released. It took over two years to get from Debian’s last release (Woody) to the current one. My experiences with Woody could be summed up as “stable, but really old”, so hopefully this new release will breathe some life back into the Debian user community.
Get it:
via ftp
Debian […]

Linux equivalents of Windows Software

GNU software provides an equivalent to almost any Windows application but for people who’re new to GNU/Linux, figuring out what they have available to them can be tricky. Photoshop doesn’t exist on *nix systems and beginners are unlikely to expect something called ‘The Gimp.’
The following website keeps an updated chart of corresponding Posix - […]

KDE 3.4.1 Released

The KDE Project has released KDE 3.4.1. They’re calling it a ‘maintenance’ release because it’s mostly bugfixes and small alterations. Despite this, the release has some much needed changes. One of the bugs that it solves has been slowing down my work all week.
The KDE Project emphasized fixes in its 50 translations […]



Categories: