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.

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?

hi,
hope can help you some.

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

cd $1
for i in *
do
	echo $i
done

below will generate three section, only in first dir, only second dir, in both dir

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

Atleast on Solaris, you can do this:

$ dircmp -s folder1 folder2 |grep -v "^ *$" |grep -v Page
./file3

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...

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":

#!/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:

ksh compare.sh folder1 folder2

Or I'm completely missing something?

rikxik, i have not the command dircmp on mac os x...

i have tried this

#!/bin/bash

var="$(ls -1 /Users/$USER/Desktop/source/ | sed 's/ /_/g')"


var1="$(ls -1 /Users/$USER/Desktop/destination/ | sed 's/ /_/g')"


var3="$var $var1"

for file in $var3
do
if [ "$var" != "$var1" ]
then
echo $file
fi
done

but i only want the file wich is not common on the 2 folders...

i imagine this code but i work with extern file and not variables....the code is good

(ls -1 /Users/$USER/Desktop/source/ | sed 's/ /_/g') > essai.txt

#echo $var

(ls -1 /Users/$USER/Desktop/destination/ | sed 's/ /_/g') >> essai.txt

cat essai.txt | sort | uniq -u