Americas

  • United States

2-Minute Linux Tips

Learn how to use a host of Linux commands in these 2-minute video tutorials from Sandra Henry-Stocker, author of the Unix as a Second Language blog.

Ep.149
Image
video

How to use the CMP command

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/

Ep.149
Sep 17, 2024 2 mins
Developer