peixe
peixe

Reputation: 1292

Compare 2 files with shell script

I was trying to find the way for knowing if two files are the same, and found this post...

Parsing result of Diff in Shell Script

I used the code in the first answer, but i think it's not working or at least i cant get it to work properly...

I even tried to make a copy of a file and compare both (copy and original), and i still get the answer as if they were different, when they shouldn't be.

Could someone give me a hand, or explain what's happening?

Thanks so much;

peixe

Upvotes: 0

Views: 13676

Answers (2)

glenn jackman
glenn jackman

Reputation: 246774

comm is a useful tool for comparing files.

The comm utility will read file1 and file2, which should be ordered in the current collating sequence, and produce three text columns as output: lines only in file1; lines only in file2; and lines in both files.

Upvotes: 0

Francisco R
Francisco R

Reputation: 4048

Are you trying to compare if two files have the same content, or are you trying to find if they are the same file (two hard links)?

If you are just comparing two files, then try:

diff "$source_file" "$dest_file" # without -q

or

cmp "$source_file" "$dest_file" # without -s

in order to see the supposed differences.

You can also try md5sum:

md5sum "$source_file" "$dest_file"

If both files return same checksum, then they are identical.

Upvotes: 6

Related Questions