Linux Commands for 99 Bottles of Beer and Disk Space - page 2
99 Bottles of Beer, df commanddu 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.
- 1Linux Top 3: Fedora 24, Peppermint 7 and Solus 1.2
- 2Linux Top 3: Alpine Linux 3.4, deepin 15.2 and Linux Lite 3.0
- 3Linux 4.7 Set to Boost Live Patching, Security and Power Management
- 4Linux 4.6 Charred Weasel adds USB 3.1 Support
- 5Linux Top 3: OpenIndiana 2016.04, Ubuntu 16.04 and Debian's New Leader