Compare 2 folders...


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare 2 folders...
# 1  
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  
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  
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  
Quote:
Originally Posted by protocomm
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  
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  
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  
Quote:
Originally Posted by protocomm
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?
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #34
Difficulty: Medium
When a computer is first powered on, the special type of absolute loader is known as the pre-boot loader.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to compare files in 2 folders and delete the large file

Hello, my first thread here. I've been searching and fiddling around for about a week and I cannot find a solution.:confused: I have been converting all of my home videos to HEVC and sometimes the files end up smaller and sometimes they don't. I am currently comparing all the video files... (5 Replies)
Discussion started by: Josh52180
5 Replies

2. Shell Programming and Scripting

Compare two folders and file content

Hi, I am having two folders where i need to compare the content of files and also to know if any new files been added and redirect the difference output in respective filename logs. For e.g.: Directory D1: f1 f2 f3 Directory D2: f1 f2 f3 f4 i Need to compare the directories... (25 Replies)
Discussion started by: rohit_shinez
25 Replies

3. Shell Programming and Scripting

Compare Directories and folders on two remote lpar

Hello, i'm trying to script to compare the same directory on the lpar. The problem is i'm using the command : find /etc -type d -ls but i cannot reach the remote lpar. I have another solution to put that command in a text file and compare with Excel. but i could be fine to have the... (7 Replies)
Discussion started by: steiner
7 Replies

4. Shell Programming and Scripting

Linux Script to compare two folders and copy missing files

Hi, I need help in shell scripting. If someone can help me, that would be great! Problem. I want Linux Script to compare two folders and copy missing files. Description. I have two directories /dir1 /dir2 I need to copy all distinct/new/unique/missing files from /dir1 and that... (1 Reply)
Discussion started by: S.Praveen Kumar
1 Replies

5. Shell Programming and Scripting

HELP! Need to compare 2 folders on 2 different systems, and copy unmatched filenames to other folder

This has been tearing my hair out. I need to: 1: compare server1:/data/archive/ to server2:/data/archive/ (through rsync, ssh, etc) 2: filenames that don't match, get copied (scp) to server2:/data/ server1 and server2 have ssh, scp, rsync access between eachother. Is there any option in... (3 Replies)
Discussion started by: damang111
3 Replies

6. Shell Programming and Scripting

How to compare files in two folders using cmp?

i recently copied 400GB of data from a NTFS drive to a ext4 drive. I want to verify that the data is 100% identical to the original. I wanted to use cmp but it only does two files. The directory that was copied contains many subdirectories and all sorts of files (not just text). So I guess... (5 Replies)
Discussion started by: fuzzylogic25
5 Replies

7. Shell Programming and Scripting

Compare files in two folders and delete missing ones

I do not know much about shell scripting so I am at a loss here. If someone can help me, that would be great! I have two directories /dir1 /dir2 I need to delete all files from /dir1 and that does not have a correspondent file in /dir2. It should NOT check file suffixes in /dir2 . Why?... (20 Replies)
Discussion started by: kaah
20 Replies

8. Shell Programming and Scripting

Compare the checksum of files in 2 different folders

Hi I have 2 different folders on different machines. they are supposed to be same but some time for unknown reason they are not. then we have to generate a report for files which are not matching. I was doing as below - cd folder1 find . -type f | sort | cksum >1.txt cd folder2 find .... (7 Replies)
Discussion started by: reldb
7 Replies

9. UNIX for Dummies Questions & Answers

To compare selective file in different folders

Hello, I am using dircmp -d <folde1> <Folder2> to compare the files from two different foldes, but this command compares for all the files. Is there any option to select only some files for comparision. For example in Folder1: file1.txt file2.txt file3.txt Folder2 file1.txt file2.txt... (0 Replies)
Discussion started by: gmahesh2k
0 Replies

10. Shell Programming and Scripting

Remote compare of folders

Hi, Is there a way (either commands/tools/scripts/logic) to compare two given folders on different unix boxes. I want to compare folder a in Unix box 'A' with folder 'b' in Unix box 'B'. I can run the script in Unix box 'A'. I am looking. for following results: files/sub folders only in a... (1 Reply)
Discussion started by: sunilav
1 Replies

Featured Tech Videos