?
Solved

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

Posted on 2014-01-30
3
Medium Priority
?
398 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 1200 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

800 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