The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To compare selective file in different folders gmahesh2k UNIX for Dummies Questions & Answers 0 05-15-2008 03:03 AM
Compare two arrays in sh or compare two fields rijeshpp Shell Programming and Scripting 0 10-31-2007 02:47 AM
Remote compare of folders sunilav Shell Programming and Scripting 1 04-04-2007 06:04 AM
Copying Folders without some folders... ;-) chimpu UNIX for Dummies Questions & Answers 5 04-26-2004 01:25 PM
Backing up Folders without some folders...;) chimpu Shell Programming and Scripting 1 04-26-2004 11:02 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2009
protocomm protocomm is offline
Registered User
  
 

Join Date: Mar 2009
Location: france, montpellier
Posts: 150
Compare 2 folders...

Hello,

I try to compare 2 folders, i explain, i have file in this 2 folder and i want to print out the difference in this folders...

ex: folder1: file1 file2 file3
folder2: file1 file2
print file3

I do a ls of the 2 folders and i use the command diff (diff $var1 $var2) without result....

Thanks for your help.
  #2 (permalink)  
Old 03-18-2009
aaaaargh aaaaargh is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 20
To compare folders I recommend you use rsync

rsync -n -avxl src/ tgt/

This will show you how src differers from tgt
Is this what you are looking for?
  #3 (permalink)  
Old 03-18-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
hi,
hope can help you some.

<filelist.sh> to list all the files under given directory

Code:
cd $1
for i in *
do
	echo $i
done
below will generate three section, only in first dir, only second dir, in both dir
Code:
sh filelist.sh dir1 > dir1file
sh filelist.sh dir2 > dir2file
echo "Those in dir1 but not dir2:"`comm -23 dir1file dir2file`
echo "Those in dir2 but not dir1:"`comm -13 dir1file dir2file`
echo "Those in both dir1 and dir2:"`comm -12 dir1file dir2file`
rm dir1file dir2file
  #4 (permalink)  
Old 03-18-2009
rikxik's Avatar
rikxik rikxik is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 250
Quote:
Originally Posted by protocomm View Post
Hello,
ex: folder1: file1 file2 file3
folder2: file1 file2
print file3
Atleast on Solaris, you can do this:
Code:
$ dircmp -s folder1 folder2 |grep -v "^ *$" |grep -v Page
./file3
  #5 (permalink)  
Old 03-19-2009
protocomm protocomm is offline
Registered User
  
 

Join Date: Mar 2009
Location: france, montpellier
Posts: 150
Thanks for your answers, but i want work with variables and not directly with the file.

With rsync as comm if i give $var instead the directory directly, i have errors...
  #6 (permalink)  
Old 03-19-2009
protocomm protocomm is offline
Registered User
  
 

Join Date: Mar 2009
Location: france, montpellier
Posts: 150
Thanks for your answers, but i want work with variables and not directly with the file.

With rsync as comm if i give $var instead the directory directly, i have errors...
  #7 (permalink)  
Old 03-19-2009
rikxik's Avatar
rikxik rikxik is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 250
Quote:
Originally Posted by protocomm View Post
Thanks for your answers, but i want work with variables and not directly with the file.

With rsync as comm if i give $var instead the directory directly, i have errors...
What are you talking about? You posted example folder1, folder2 so the answers were provided accordingly. What is stopping you from putting the commands in a script, say "compare.sh":

Code:
#!/usr/bin/ksh
f1=$1
f2=$2
dircmp -s $f1 $f2 |grep -v "^ *$" |grep -v Page
Then you can simply pass the arguments to the script:

Code:
ksh compare.sh folder1 folder2
Or I'm completely missing something?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0