[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

linux shell command  du  - directory size summaries

Posted on 2011-10-19
7
Medium Priority
?
333 Views
Last Modified: 2012-06-27
what command and option combinations can i execute to get
ONE LEVEL BELOW/WITHIN
of all subdirectories below the current (or specified) default directory level for showing total size contained in each directory.

ex:  /home/user/*  
to list the next level (only) of directories under  user/   and the total summary size of files contained therein/within.

/home/user/a   1200         // all files and directories under   a/   total up to about 1200
/home/user/b   300
/home/user/c   13000

etc.
output format is not critical, as long as it's readable.

thanks
0
Comment
Question by:willsherwood
  • 4
  • 3
7 Comments
 
LVL 21

Accepted Solution

by:
Papertrip earned 2000 total points
ID: 36997337
Use --max-depth
--max-depth=N
              print the total for a directory (or file, with --all) only if it is N or fewer levels below the command line argument;  --max-depth=0 is the same as --summarize

du -h --max-depth=1 /dir

Open in new window

[root@broken ~]# du -h --max-depth=1 /var
6.8M    /var/log
1.2M    /var/www
4.0K    /var/games
16K     /var/tmp
4.0K    /var/nis
32K     /var/opendkim

Open in new window

0
 

Author Closing Comment

by:willsherwood
ID: 36997363
YAY thanks.
0
 

Author Comment

by:willsherwood
ID: 36997373
follow up: how to show as consistent integer sizes so i can  | sort
the above shows with units  G  M  K
thanks
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 21

Expert Comment

by:Papertrip
ID: 36997385
Please ask that in a new question and someone will be happy to answer you :)
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 36997477
On 2nd thought, since you are asking that because of something I put into the syntax... just remove the h and the default display size will be in kilobytes, easy to sort.
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 36997478
err -h rather
0
 

Author Comment

by:willsherwood
ID: 36997485
gotcha, perfect, thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month18 days, 9 hours left to enroll

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question