Comparing two folders


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing two folders
# 1  
Old 06-11-2012
Comparing two folders

Hi,

Can you tell me how to compare two directories and write the differing files to some other folder?
# 2  
Old 06-11-2012
Use diff recursively and redirect the output to a file.

Regards,
Alister
# 3  
Old 06-11-2012
thats correct, but i want to copy the whole differing files not the names only.

Is it possible?Smilie
# 4  
Old 06-11-2012
It would help if you stated precisely what you are trying to accomplish by at least creating two directories with a two or three simple files and then ls output of the desired result.

How do you expect to accomodate two differing files with the same name in the same destination folder? Do you require a specific renaming scheme? If a file exists in one directory but not the other, should it be copied or not? Should subdirectories be visited as well?

If you have any other special requirements, please state them now before people waste time on unhelpful suggestions.

Regards,
Alister
# 5  
Old 06-11-2012
try this one, hope it works for you

Code:
 
diff <dir1> <dir2>| xargs -I FNAME  echo FNAME>> tmp_file

for filepath in `cat tmp_file`
do
     dir_name=`echo $filepath|cut -d" " -f3|cut -d":" -f1`
     file_name=`echo $filepath|cut -d" " -f4`
     cp $dir_name/$file_name <target_dir> 2>>error_log
done

/bin/rm -f tmp_file

Use absolute path for directory listing.
# 6  
Old 06-11-2012
Thank you all.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

2. Shell Programming and Scripting

Comparing folders - autocopy script

Hey Guys, first of all: I'm new to unix and im not very experienced. I've bought a rapsberry pi and i want it to be the backup-machine for my SD-Cards while im travelling (attached ssd, card reader, a small touch-tft) I managed to modify it a litte bit (its sending information bubbles to the... (3 Replies)
Discussion started by: Eomer
3 Replies

3. UNIX for Dummies Questions & Answers

Archive folders and sub folders

Hi Can i archive folder and folders in with the tar command My files are located in subfolders Eg: Folder1/Folder1_1/*.pdf Folder1/Folder1_2/*.pdf Folder1/Folder1_3/*.pdf so i would like to tar all the files in Folder1_1 and Folder1_2 only not Folder1_3 that should be done next... (2 Replies)
Discussion started by: cnrj
2 Replies

4. Shell Programming and Scripting

Copy between two different folders containing same sub-folders

I have a folder like this ls input1 dir1 dir2 dir3 file1 file2 file3 dir1, dir2 and dir3 are sub-folders inside the folder input1 ls input2 dir1 dir2 dir3 file1 file2 file3 My dir1 in input1 folder has files f1, f2, f3 and f4. My dir1 in input2 folder has file f4 and f5. ... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Solaris

Folders with more than one 'owner'

I have a peculiar problem. I have a particular directory with the following characteristics: -bash-3.00# ls -lah total 18 drwxr-x--- 7 gandalf shire 512 jul 3 07:20 . drwxr-x--- 11 gandalf shire 512 mai 10 2010 .. drwxr-xr-x 6 gandalf shire 3,0K jul 24 19:25 brasdeff drwxr-xr-x... (9 Replies)
Discussion started by: poyato
9 Replies

6. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

7. Shell Programming and Scripting

Making 99 folders 99 folders deep

I am trying to make a unix shell script that will make 99 folders 99 deep (counting the first level folders). So far i have made it make the first 99 folders and 99 more in all of the folders. The only problem is the only way i have found is copying and pasting part of the script over and over and... (18 Replies)
Discussion started by: YukonAppleGeek
18 Replies

8. Shell Programming and Scripting

Comparing Two Binary Folders

I am a beginner to all of this but undertand the basic principles. I am currently working on a large task and struggling with a the final part. I have two files, folder 1 contains a list of around 20 files in binary (possibly treated as arrays?) folder 2 contains several files and sub... (2 Replies)
Discussion started by: puzzler
2 Replies

9. UNIX for Dummies Questions & Answers

Copying Folders without some folders... ;-)

I am in a fix....... I have to write a backup script to backup say Folder A. Folder A contains n folders 1,2 ,3 .....n. my script should copy A without folder 2 & 3. Is there anyway I can do it without writing individual copy commands???? Please help.... (5 Replies)
Discussion started by: chimpu
5 Replies

10. Shell Programming and Scripting

Backing up Folders without some folders...;)

I am in a fix....... I have to write a backup script to backup say Folder A. Folder A contains n folders 1,2 ,3 .....n. my script should copy A without folder 2 & 3. Is there anyway I can do it without writing individual copy commands???? Please help.... (1 Reply)
Discussion started by: chimpu
1 Replies
Login or Register to Ask a Question