Inquiry:How to compare the contents of two folders?
Dear All
Please be informed that on my RedHat 7.2 server I have two conf folders . I want to compare their contents to see which files are different in size & content . Can you please do me favor and let me know how can I accomplish this ? Let me thank you in advance |
The all mighty diff should get you going.
It has a recursive option, an option that tells you if things just differ (normaly it prints out every diffrence), can tell you if files are missing. Just dig around the man page and see what suits. Cheers Zhjim |
Dear Hadimotamedi,
e.g. you can try the following: ls -l /path/to/conf1_dir > conf1.lst ls -l /path/to/conf2_dir > conf2.lst diff conf1.lst conf2.lst This will show you differences between the contents of the two directories. If you need to compare two files only to know if they differ (or not), use md5sum file1 md5sum file2 and see if the checksums are the same or not. To find the difference _in_ the contents of two files, use diff once again: diff file1 file2 You can pipe the above diff command if you want: diff file1 file 2 | grep -e '^< ' -e '^> ' to have only those rows which show the different lines. etc. Have a good day, KEA. |
Thank you for your reply . Please be informed that in my application the two files have similar data in their rows (but not sorted) . I need to find how many rows they have in common (in other words , how many rows with the same data in both of the files) ? As I understand , the diff just compares the rows in one-to-one correspondence and it does not take into account of the similairty between say row#1 in the first file with say row#3 in the second file . Can you please let me know how to modify it to get the desired result ?
Thank you in advance Quote:
|
Code:
mkdir /tmp/first_dir |
Thank you for your help . Please be informed that I tried for your code but it returned just the followings :
" #diff -r /tmp/first_dir /tmp/second_dir Only in /tmp/first_dir : Edit3 Only in /tmp/second_dir: Edit4 " Please be informed that the two files that I want to compare are the Edit3 & Edit4 that I have copied them into the intended folders . Can you please let me know why the output of your code is so unclear ? Actually , I want to compare these two files but not in line-by-line basis . Thank you in advance Quote:
|
The -r option to diff lets it recurseivly walk directories. But for this to work the files have to have the same name.
Try this Code:
diff /tmp/first_dir/Edit3 /tmp/second_dir/Edit4 Import things are. Have both files sorted with sort and save them to individual files. Then diff first_file second_file |
Quote:
Evo2. |
All times are GMT -5. The time now is 08:09 AM. |