Slackware This Forum is for the discussion of Slackware Linux.
|
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
02-04-2014, 08:12 PM
|
#1
|
Member
Registered: May 2006
Posts: 125
Rep:
|
Best directory size report command?
I'm trying to get a quick overview of my web folder sizes.
like /var/http/www.whatever.com
I was using something like
du -sk * | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'
to get report like
848.0K www.whatever.com
1.4M www.whatever2.com
but that command does not work on my new slackware 14.1 server now. It was fine on my older slackware 10 server.
Does anyone have any suggestions on something that can generate a report like that? also sorted?
|
|
|
02-04-2014, 08:14 PM
|
#2
|
Senior Member
Registered: Jul 2004
Location: Jogja, Indonesia
Distribution: Slackware-Current
Posts: 4,771
|
Why not du -h ?
|
|
|
02-04-2014, 08:32 PM
|
#3
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
I usually use ncdu for tasks like that. It is an interactive tool, but when used with the -o option it will save a report to a file that can later be opened with ncdu using the -f option.
|
|
1 members found this post helpful.
|
02-04-2014, 09:05 PM
|
#4
|
Member
Registered: Apr 2011
Location: British Columbia, Canada
Posts: 304
Rep:
|
du -sh *
|
|
|
02-04-2014, 09:36 PM
|
#5
|
Member
Registered: May 2010
Posts: 621
Rep:
|
du is great, and so is filelight
|
|
|
02-04-2014, 10:13 PM
|
#6
|
Member
Registered: May 2006
Posts: 125
Original Poster
Rep:
|
Quote:
Originally Posted by TobiSGD
I usually use ncdu for tasks like that. It is an interactive tool, but when used with the -o option it will save a report to a file that can later be opened with ncdu using the -f option.
|
Can Ncdu output just a raw text report?
|
|
|
02-05-2014, 02:21 AM
|
#7
|
Member
Registered: May 2004
Distribution: BSD
Posts: 269
Rep:
|
There is also a small utility called dirsize. Its primary purpose is for use with shell prompts, but can be used as a stand-alone program as well. From the web site:
Quote:
This tool outputs the aggregate size of all files in one or more directories, defaulting to the current directory. It does not recurse.
|
So it might not be exactly what you're looking for.
|
|
|
02-05-2014, 04:45 AM
|
#8
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
Quote:
Originally Posted by kenw232
Can Ncdu output just a raw text report?
|
Those reports are raw text and contain filename, real size, size on disk and inode number. Here is an example, run on my /etc/slackpkg directory:
Code:
[1,0,{"progname":"ncdu","progver":"1.10","timestamp":1391593344},
[{"name":"/etc/slackpkg","asize":4096,"dsize":8192,"dev":2049,"ino":6333},
{"name":"blacklist","asize":1021,"dsize":4096,"ino":1227235},
{"name":"blacklist~","asize":1004,"dsize":4096,"ino":1135329},
{"name":"greylist","asize":543,"dsize":4096,"ino":7156},
{"name":"mirrors","asize":25508,"dsize":28672,"ino":1773597},
{"name":"mirrors~","asize":25511,"dsize":28672,"ino":7685},
{"name":"notifymsg.conf","asize":1750,"dsize":4096,"ino":7069},
{"name":"slackpkg.conf","asize":5893,"dsize":8192,"ino":7687},
{"name":"slackpkg.conf~","asize":5894,"dsize":8192,"ino":7688},
{"name":"slackpkgplus.conf","asize":4459,"dsize":8192,"ino":1773592},
{"name":"slackpkgplus.conf.new~","asize":5136,"dsize":8192,"ino":445708},
{"name":"slackpkgplus.conf.orig","asize":2259,"dsize":4096,"ino":507979},
{"name":"slackpkgplus.conf~","asize":4488,"dsize":8192,"ino":6349},
[{"name":"templates","asize":1,"ino":13813}]]]
|
|
|
02-05-2014, 09:05 AM
|
#9
|
Member
Registered: Apr 2010
Location: Geneva - Switzerland ( Bordeaux - France / Montreal - QC - Canada)
Distribution: Slackware 14.2 - 32/64bit
Posts: 609
|
Quote:
Originally Posted by kenw232
Can Ncdu output just a raw text report?
|
ncdu is "just" a ncurse gui over du... So to output text, just use du...
|
|
|
02-05-2014, 09:56 AM
|
#10
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep:
|
I've used this for years:
Code:
#!/bin/bash
/usr/bin/du -sk ./* | /usr/bin/sort -n | /usr/bin/awk 'BEGIN{ pref[1]="K"; pref[2]="M"; pref[3]="G";} { total = total + $1; x = $1; y = 1; while( x > 1024 ) { x = (x + 1023)/1024; y++; } printf("%g%s\t%s\n",int(x*10)/10,pref[y],$2); } END { y = 1; while( total > 1024 ) { total = (total + 1023)/1024; y++; } printf("Total: %g%s\n",int(total*10)/10,pref[y]); }'
outputs similar to:
Code:
12K ./Desktop
14.2M ./wun
51M ./Bin
171.1M ./Pictures
17.5G ./Documents
26.5G ./Downloads
32.3G ./VboxVMs
Total: 74.7G
Edit: Obviously, I ran this in my ~ directory - YMMV
Last edited by Habitual; 02-05-2014 at 10:56 AM.
|
|
2 members found this post helpful.
|
02-05-2014, 10:02 AM
|
#11
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,960
|
this is already implemented (total is not included):
du -sh * | sort -h
|
|
|
02-05-2014, 02:32 PM
|
#12
|
Member
Registered: May 2006
Posts: 125
Original Poster
Rep:
|
Quote:
Originally Posted by lems
There is also a small utility called dirsize. Its primary purpose is for use with shell prompts, but can be used as a stand-alone program as well. From the web site:
So it might not be exactly what you're looking for.
|
dirsize is nice but I'm not smart enough to sort it by size. dirsize -H * | sort -n doesn't cut it?
|
|
|
02-05-2014, 02:35 PM
|
#13
|
Member
Registered: May 2006
Posts: 125
Original Poster
Rep:
|
Code:
#!/bin/bash
/usr/bin/du -sk ./* | /usr/bin/sort -n | /usr/bin/awk 'BEGIN{ pref[1]="K"; pref[2]="M"; pref[3]="G";} { total = total + $1; x = $1; y = 1; while( x > 1024 ) { x = (x + 1023)/1024; y++; } printf("%g%s\t%s\n",int(x*10)/10,pref[y],$2); } END { y = 1; while( total > 1024 ) { total = (total + 1023)/1024; y++; } printf("Total: %g%s\n",int(total*10)/10,pref[y]); }'
This is a good replacement for my problem. Thanks.
|
|
|
02-05-2014, 02:47 PM
|
#14
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep:
|
Quote:
Originally Posted by kenw232
Code:
#!/bin/bash
/usr/bin/du -sk ./* | /usr/bin/sort -n | /usr/bin/awk 'BEGIN{ pref[1]="K"; pref[2]="M"; pref[3]="G";} { total = total + $1; x = $1; y = 1; while( x > 1024 ) { x = (x + 1023)/1024; y++; } printf("%g%s\t%s\n",int(x*10)/10,pref[y],$2); } END { y = 1; while( total > 1024 ) { total = (total + 1023)/1024; y++; } printf("Total: %g%s\n",int(total*10)/10,pref[y]); }'
This is a good replacement for my problem. Thanks.
|
Glad you like it and it helps you out.
|
|
|
All times are GMT -5. The time now is 05:42 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|