Solved

compare two directories and list size of all sub directories in two columns in linux shell script

Posted on 2014-01-30
3
379 Views
Last Modified: 2014-01-31
Hi,
Would like compare two directories (recursively) and display only the size in GB from all sub directories in two columns in linux

subdirname      pdir1        pdir2
one                    1GB      1GB
two                    1GB      1.1GB
three                 1GB      1.2GB
four                  1.1GB      1GB

Thanks in advance
0
Comment
Question by:enthuguy
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 300 total points
ID: 39822755
(cd pdir1 ; du -h | awk '{print $2,$1}' | sort ) > d1
(cd pdir2 ; du -h | awk '{print $2,$1}' | sort ) > d2
join d1 d2
0
 
LVL 19

Expert Comment

by:simon3270
ID: 39824357
Small change - that would display the size of each file under the directory, and use whatever size was appropriate.  To force it to use GB, and do summary sizes of the subdirectories (or files) directly in  the two directories, the du command changes from "du -h" to:
    du --block-size=G -s *
0
 

Author Comment

by:enthuguy
ID: 39825491
Thanks very much ..that helped.

Tried this with slight change
(cd pdir1 ; du -sh * | awk '{print $2,$1}' | sort ) > d1
(cd pdir2 ; du -sh * | awk '{print $2,$1}' | sort ) > d2
join d1 d2
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS RDS 3 65
Assess most serious Linux privilege escalation bug 17 146
i can not do linux commands in cygwin windows 10 6 60
expectj telnet failing 5 19
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

914 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now