Solved

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

Posted on 2014-01-30
3
376 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

747 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

12 Experts available now in Live!

Get 1:1 Help Now