Welcome to the Linux Foundation Forum!
Hi @Pangar , Please post in the Bootcamp forum, so Flavia can assist you. Regards, Luis.
- Last Active
Hi Luis, can you advise how I can compare the contents of multiple files in a directory? I know that "$diff file1 file2" allow me to compare two files. How do I do this for multiple files in a directory or different directories?
Thank you.0April 14
luisviveropenaHi MUkaoma, how that can be useful? I mean, do you have two directories with very similar content, and you want to know is there is any difference between the same filenames in both directories? If that's not the case, the files may differ a lot.
Anyway, you may use the "-r" flag, as shown in the "man diff" page:
recursively compare any subdirectories found
MUkaomaThanks Luis. I know that "$diff -r directory1 directory2" allow me to compare all files (and sub-directory files) contained in directory1 and directory2. Suppose I have 10 files contained in directory1, how can I compare these 10 files in directory1? Is there an easier command better than "$diff ../directory1/file1 ../directory1/file2 ../directory1/file3 ... ../directory1/file10"?
luisviveropenaSo you want to compare one file against all the 9 in the same directory? Or you want to compare all the files between themselves? I guess you can do a "for" cycle and do the comparison you want. Anyway, if I'm not wrong, you can compare two files at once only (using diff).
MUkaomaOk, thank you. To reiterate what you said,
1. I can either use a "for" loop to compare all the files, one to another, in the directory, or
2. compare two files at a time using the "$diff file1 file2"
luisviveropenaYep, I said that. It's up to you what's the best solution for your specific case. If the files are a lot, not only 10, then you may script it.