Compare two directory listings
November 8th, 2006 toydi Posted in comm, process substitution, Text Manipulation | Hits: 114246 | 16 Comments »
Given two directories: ~/dir-new/ and ~/dir/,
$ ls ~/dir-new/
file-01.txt
file-02.txt
file-new.txt
$ ls ~/dir/
file-01.txt
file-02.txt
file-old.txt
To compare them:
comm <(ls ~/dir-new/) <(ls ~/dir)
comm compares two files line-by-line and displays 3 columns : 1) lines unique to first file, 2) lines unique to second file, 3) lines appear in both files.
file-01.txt
file-02.txt
file-new.txt
file-old.txt
To remove Column 1, try 'comm -1', and 'comm -23' will remove Column 2 and 3.
And this, '<(ls ~/dir-new/)', they call it as process substitution. Since comm only reads from files, '<( )' pretends itself as a file by returning a filename, which is read-only, containing the output of 'ls ~/dir-new/'.
In short, we may think '<(commands)' as a pseudo, read-only file:
$ ls -l <(true)
lr-x------ 1 toydi toydi 64 2006-11-08 14:30 /dev/fd/63 -> pipe:[28600]







October 23rd, 2007 at 8:46 am
diff dir dir-new
give er a try!
March 6th, 2008 at 10:17 am
i like the ‘comm’ command, diff was giving me grief trying to find unique files between 2 dirs so i could copy/sync things up.
cheers for this tip!
June 23rd, 2010 at 4:41 pm
Good one!! Google shall rank this page as 1st result instead of 5th result :P
December 17th, 2010 at 9:53 pm
diff is pretty easy although i’m finding comm to be neat. I love new things.
Solve your diff unique record issues using ‘uniq -u’ after a ‘sort’
February 16th, 2011 at 4:11 am
Nice one, been looking for this.
The problem with diff is that it will compare every file which can be very slow depending an the # and size of files. If you only want to compare dir listings, this is the way.
March 3rd, 2011 at 5:36 am
Cool! This even works in a recursive way:
comm <(cd DIRONE && find |sort) <(cd DIRTWO && find |sort) |less
May 4th, 2011 at 12:00 pm
Oh!!! Thank you. Diff is slow. Sync is weird. This is simple.
December 3rd, 2011 at 11:58 am
This is very fascinating, You are an overly skilled blogger. I have joined your rss feed and look ahead to seeking more of your wonderful post. Also, I have shared your site in my social networks
December 20th, 2011 at 9:49 pm
Valuable information. Fortunate me I found your website by accident, and I’m surprised why this twist of fate did not took place in advance! I bookmarked it.
April 22nd, 2013 at 5:40 am
[…] in DIR1, 2 – files only in DIR2, 3 – files only in DIR3For more details look at this blog post.use “diff -qr” to get the different files and then filter out the file comparison with […]
February 9th, 2014 at 6:20 pm
One must practice the comic scripts beforehand at home.
Think of this as a way to document your improvements over time, and eventually
it will be a very effective PR tool. These surgeries are a matter
of personal preference, peer pressure from fellow entertainers and the need to
maintain an unrealistic image that is associated with them.
April 1st, 2014 at 3:35 pm
With Natural Human Growth Hormone Releasers, like Gen – F20, it is possible to help our bodies
overcome signs of growing older. Studies show that seniors who conserve
a link with an online community have better probability
of being in a sound body, and staying this way from the years.
If additionally, you will use them for a long period, in that case your body’s capacity to generate bodily hormones
naturally will likely be decreased and ultimately, you’ll grow to be dependent upon
those shots.
April 3rd, 2014 at 4:07 am
We cannot think our lives without phones, especially smart phones.
This listing of just the best Verizon smartphones analyzes everything the organization can give and narrows your
decision into just the best device. The cameras on phones – We’ve seen the goal of
phones change drastically within the years.
April 9th, 2014 at 8:06 pm
I am truly grateful to the owner of this site who has shared this great piece of writing at at this time.
April 27th, 2014 at 1:56 am
Since more tissue mass is present, more
blood may then be saved in the spot resulting to harder and
long-lasting erections that boost virility,
performance and satisfaction. For generations, herbs and herbal products happen to
be considered extremely effective such matters. Calcium from milk
is conveniently acknowledged from the body and processed.
January 20th, 2015 at 12:49 am
[…] It gives you 3 columns: 1 – files only in DIR1, 2 – files only in DIR2, 3 – files only in DIR3 For more details look at this blog post. […]