Linux Commands for 99 Bottles of Beer and Disk Space - page 2
99 Bottles of Beer, df command
du shows the total space used by my home directory:$ du -hs ~ 122G /home/carlahs means use human-readable numbers and show the total for the whole directory, and ~ is a shortcut for "my own home directory". Use this to get the total size of any directory. If you leave off the s it lists every subdirectory and file. You can also get the size of any individual file:
$ du -h worried-man.wav 18M worried-man.wavOr all the same type of files in the current directory:
$ du -h *.jpg 144K jpgtest1.jpg 132K jpgtest.jpg 28K nascarcap.jpg 128K firefox-win.jpg 48K funny-pictures-cat-is-grumpy.jpgThis finds the ten biggest directories or files in my home directory:
$ du -a ~ | sort -nr | head -n 10 127353376 /home/carla 122939388 /home/carla/sda1 55389844 /home/carla/sda1/photos 40650788 /home/carla/sda1/Photos 37020884 /home/carla/sda1/photos/2007 23911504 /home/carla/sda1/carla 17702480 /home/carla/sda1/photos/2008 16547200 /home/carla/sda1/Photos/2007-sept-montana 16547200 /home/carla/sda1/photos/2007/2007-sept-montana 5634812 /home/carla/sda1/carla/picturesIf you leave off the a option it only reports directories. I can't use the human-readable option because that does not sort correctly. I'm sure there is some nifty regular expression that knows 1000M is bigger than 1000K, but I haven't figured it out yet. Ace admins script these commands to monitor disk usage, and to send them alerts when disks get too full.
See man df, man du, man bash, man sort, and the excellent book Learning the Bash Shell to learn more.
Carla Schroder is the author of the Linux Cookbook and the Linux Networking Cookbook (O'Reilly Media), the upcoming "Book of Audacity" (NoStarch Press), a lifelong book lover, and the managing editor of LinuxPlanet and Linux Today.
- Skip Ahead
- 1. 99 Bottles of Beer, df command
- 2. 99 Bottles of Beer, df command
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.