Solved

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

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

770 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