Americas

  • United States

How to use the CMP command

Overview

In this Linux tip, we’re going to look at the cmp command. It’s a command that allows you to compare the content of two text files. If the files that you are comparing are identical, there will be no output. Here’s an example: $ cmp file1 file2 $ Here’s a file listing … $ ls -l file1 file2 -rw-r--r--. 1 shs shs 104 Aug 21 16:19 file1 -rw-r--r--. 1 shs shs 104 Sep 7 12:11 file2 If the files are different, you can expect to see output like this that describes where the first difference is located. $ cmp file1 file3 file1 file3 differ: byte 12, line 1 These commands display the content of the files: $ cat file1; echo ===============; cat file3 Kids, the seven basic food groups are gum, puff pastry, pizza, pesticides, antibiotics, and milk duds!! =============== Kids, the six basic food groups are fruits, vegetables, grains, protein and dairy and milk duds!! Notice the 12th character of file1 is an “e” and the 12th character of file2 is an “I”. Closing: That’s your Linux tip for the cmp command. It tells you if files are different and, if so, reports the location of the first difference. If you have questions or would like to suggest a topic, please add a comment below. And don’t forget to subscribe to the InfoWorld channel on YouTube. ------------------------------­---- SUBSCRIBE: http://www.youtube.com/subscription_center?add_user=InfoWorld FACEBOOK: https://www.facebook.com/Infoworld/ TWITTER: https://twitter.com/Infoworld WEBSITE: http://www.infoworld.com/

Register Now