One line Perl Script to determine the largest file sizes on a Linux Server

du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf ("%6.1f\t%s\t%25s %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}' | more
This one line Perl script will display the smallest to the largest files sizes in all directories on a server.
Sample Output
4.0	K	                       **  ./bin
   4.0	K	                       **  ./.config/gnome-main-menu
   4.0	K	                       **  ./.config/.mono/certs/Trust
   4.0	K	                       **  ./Desktop
   4.0	K	                       **  ./.fvwm
   4.0	K	                       **  ./.gconfd
   4.0	K	                       **  ./.gnome2/accels
   4.0	K	                       **  ./.gnome2/keyrings
   4.0	K	                       **  ./.gnome2/nautilus-scripts
   4.0	K	                       **  ./.gnome2_private
   4.0	K	                       **  ./.gnupg/private-keys-v1.d
   4.0	K	                       **  ./.kde/share/config
   4.0	K	                       **  ./.mozilla/firefox/9ikhdhm7.default/extensions
   4.0	K	                       **  ./netv/netvault/clientpackages
   4.0	K	                       **  ./netv/netvault/extrabkl
   4.0	K	                       **  ./netv/netvault/extrapackages
   4.0	K	                       **  ./.qt
   4.0	K	                       **  ./.skel
   4.0	K	                       **  ./.wapi
   4.0	K	                       **  ./.zenuser.gconf.defaults
   4.0	K	                       **  ./.zenuser.gconf.mandatory
   8.0	K	                      ***  ./.config/.mono/certs
   8.0	K	                      ***  ./Documents
   8.0	K	                      ***  ./firefox/firefox/defaults/pref
   8.0	K	                      ***  ./.gconf/apps/gnome-settings/gnome-panel
   8.0	K	                      ***  ./.gconf/apps/nautilus/preferences
   8.0	K	                      ***  ./.gconf/apps/panel/applets/clock_screen0/prefs
   8.0	K	                      ***  ./.gconf/apps/panel/applets/main_menu_screen0
   8.0	K	                      ***  ./.gconf/apps/panel/applets/mixer_screen0
   8.0	K	                      ***  ./.gconf/apps/panel/applets/notification_area_screen0
   8.0	K	                      ***  ./.gconf/apps/panel/applets/show_desktop_button_screen0
   8.0	K	                      ***  ./.gconf/apps/panel/applets/tomboy_screen0
   8.0	K	                      ***  ./.gconf/apps/panel/applets/window_list_screen0/prefs
   8.0	K	                      ***  ./.gconf/apps/panel/general
   8.0	K	                      ***  ./.gconf/apps/panel/global
   8.0	K	                      ***  ./.gconf/apps/panel/toplevels/bottom_panel_screen0/background
   8.0	K	                      ***  ./.gconf/desktop/gnome/accessibility/keyboard
   8.0	K	                      ***  ./.gconf/desktop/gnome/background
   8.0	K	                      ***  ./.gconf/desktop/gnome/peripherals/keyboard/host-posadm1/0
   8.0	K	                      ***  ./.gconf/system/http_proxy
   8.0	K	                      ***  ./.gconf/system/proxy
   8.0	K	                      ***  ./.gnome2/share/cursor-fonts
   8.0	K	                      ***  ./.gnome2/share/fonts
   8.0	K	                      ***  ./.gnome/gnome-vfs
   8.0	K	                      ***  ./.kde/share
   8.0	K	                      ***  ./.nautilus/metafiles
   8.0	K	                      ***  ./src/.tmp_versions
  12.0	K	                      ***  ./.config/.mono
  12.0	K	                      ***  ./firefox/firefox/defaults
  12.0	K	                      ***  ./.gconf/apps/gnome-settings
  12.0	K	                      ***  ./.gconf/apps/nautilus
  12.0	K	                      ***  ./.gconf/desktop/gnome/accessibility
  12.0	K	                      ***  ./.gconf/desktop/gnome/peripherals/keyboard/host-posadm1
  12.0	K	                      ***  ./.kde
  12.0	K	                      ***  ./.mozilla/firefox/9ikhdhm7.default/chrome
  12.0	K	                      ***  ./.nautilus
  12.0	K	                      ***  ./.thumbnails/fail/gnome-thumbnail-factory
  16.0	K	                     ****  ./.gconf/apps/panel/applets/clock_screen0
  16.0	K	                     ****  ./.gconf/apps/panel/applets/window_list_screen0
  16.0	K	                     ****  ./.gconf/apps/panel/toplevels/bottom_panel_screen0
  16.0	K	                     ****  ./.gconf/desktop/gnome/peripherals/keyboard
  16.0	K	                     ****  ./netv/netvault/eula/Chinese/BIG5
  16.0	K	                     ****  ./netv/netvault/eula/ChineseSimp/GB2312
  16.0	K	                     ****  ./netv/netvault/eula/Korean/EUC-KR
  16.0	K	                     ****  ./.thumbnails/fail
  20.0	K	                     ****  ./firefox/firefox/chrome/icons/default
  20.0	K	                     ****  ./.gconf/apps/panel/toplevels
  20.0	K	                     ****  ./.gconf/desktop/gnome/peripherals
  20.0	K	                     ****  ./.gconf/system
  20.0	K	                     ****  ./.gnome2/share
  20.0	K	                     ****  ./.kbd
  20.0	K	                     ****  ./netv/netvault/eula/French/ISO-8859-1
  20.0	K	                     ****  ./netv/netvault/eula/JapaneseEUC/EUC-JP
  20.0	K	                     ****  ./.thumbnails
  24.0	K	                     ****  ./firefox/firefox/chrome/icons
  24.0	K	                     ****  ./firefox/firefox/extensions/{972ce4c6-7e08-4474-a285-3208198ce6fd}
  24.0	K	                     ****  ./netv/netvault/eula/English
  24.0	K	                     ****  ./netv/netvault/eula/German/ISO-8859-1
  28.0	K	                    *****  ./.config
  28.0	K	                    *****  ./firefox/firefox/chrome
  28.0	K	                    *****  ./firefox/firefox/extensions
  28.0	K	                    *****  ./firefox/firefox/searchplugins
  28.0	K	                    *****  ./.gnome
  28.0	K	                    *****  ./.gnupg
  32.0	K	                    *****  ./netv/netvault/eula/Chinese
  32.0	K	                    *****  ./netv/netvault/eula/ChineseSimp
  36.0	K	                    *****  ./.gnome2
  40.0	K	                    *****  ./firefox/firefox/icons
  40.0	K	                    *****  ./netv/netvault/eula/Korean
  44.0	K	                    *****  ./.gconf/desktop/gnome
  44.0	K	                    *****  ./netv/netvault/eula/French
  44.0	K	                    *****  ./zlmagent/data/locale/en_US/LC_MESSAGES
  48.0	K	                    *****  ./.gconf/desktop
  48.0	K	                    *****  ./.metacity/sessions
  48.0	K	                    *****  ./netv/netvault/eula/German
  48.0	K	                    *****  ./netv/netvault/eula/JapaneseEUC
  48.0	K	                    *****  ./.ssh
  48.0	K	                    *****  ./zlmagent/data/locale/en_US
  52.0	K	                    *****  ./.metacity
  52.0	K	                    *****  ./zlmagent/data/locale/pt_BR/LC_MESSAGES
  56.0	K	                   ******  ./zlmagent/data/locale/pt_BR
  60.0	K	                   ******  ./zlmagent/data/locale/de_DE/LC_MESSAGES
  60.0	K	                   ******  ./zlmagent/data/locale/es_ES/LC_MESSAGES
  60.0	K	                   ******  ./zlmagent/data/locale/fr_FR/LC_MESSAGES
  64.0	K	                   ******  ./.mozilla/firefox/9ikhdhm7.default/bookmarkbackups
  64.0	K	                   ******  ./zlmagent/data/locale/de_DE
  64.0	K	                   ******  ./zlmagent/data/locale/es_ES
  64.0	K	                   ******  ./zlmagent/data/locale/fr_FR
  76.0	K	                   ******  ./.gconf/apps/panel/applets
 116.0	K	                  *******  ./.gconf/apps/panel
 124.0	K	                  *******  ./zlmagent/readmes
 144.0	K	                  *******  ./.gconf/apps
 148.0	K	                  *******  ./squid-old
 168.0	K	                  *******  ./netv/netvault/serverpackages
 168.0	K	                  *******  ./zlmagent/data/configureScripts
 184.0	K	                  *******  ./.gstreamer-0.10
 216.0	K	                 ********  ./.gconf
 232.0	K	                 ********  ./firefox/firefox/components
 260.0	K	                 ********  ./zlmagent/data/eulas
 272.0	K	                 ********  ./netv/netvault/eula
 300.0	K	                 ********  ./zlmagent/data/locale
 340.0	K	                 ********  ./.vmware/VMware vCenter Converter Standalone/Logs
 348.0	K	                 ********  ./.vmware/VMware vCenter Converter Standalone
 352.0	K	                 ********  ./.vmware
 624.0	K	                *********  ./firefox/firefox/dictionaries
   1.4	M	               **********  ./zlmagent/data/packages/runtime-deps/sles-10-i586
   1.4	M	               **********  ./zlmagent/data/packages/runtime-deps
   1.6	M	              ***********  ./zlmagent/data/packages/imaging/sles-10-i586
   1.6	M	              ***********  ./zlmagent/data/packages/imaging
   1.9	M	              ***********  ./src
   1.9	M	              ***********  ./.mozilla/firefox/9ikhdhm7.default/Cache
   3.4	M	             ************  ./netv/netvault/packages
   3.6	M	             ************  ./zlmagent/data/packages/sles-10-i586/sles-10-i586
   3.6	M	             ************  ./zlmagent/data/packages/sles-10-i586
   5.0	M	             ************  ./.mozilla/firefox/9ikhdhm7.default
   5.0	M	             ************  ./.mozilla/firefox
   5.0	M	             ************  ./.mozilla
   5.9	M	            *************  ./scripts
  14.0	M	           **************  ./zlmagent/data/packages/mono/sles-10-i586
  14.0	M	           **************  ./zlmagent/data/packages/mono
  24.9	M	          ***************  ./netv/netvault
  24.9	M	          ***************  ./netv
  25.9	M	          ***************  ./zlmagent/data/packages/client/sles-10-i586
  25.9	M	          ***************  ./zlmagent/data/packages/client
  28.4	M	          ***************  ./firefox/firefox
  46.5	M	         ****************  ./zlmagent/data/packages
  47.7	M	         ****************  ./zlmagent/data
  47.8	M	         ****************  ./zlmagent
  57.9	M	         ****************  ./firefox
  92.8	M	        *****************  ./acro
 184.5	M	       ******************  ./servername-backup
 437.2	M	      *******************  .

1
By: Q_Element
2012-02-07 15:49:19

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: