Sep 18 2006

Unix “Diff” Command

Last week, I released the newest version of Call Log to the Lamson Information Desk. However, when it was released, there was a serious bug that caused the info desk to stop productively functioning. It was getting to the point where nothing was working and we had to roll back an older version of Call Log before that release.

Needing to compare differences in the files, Zach told me about the “Diff” command in Unix which allows you to compare two different files and it will inform you of the changes.

Standard Syntax
[test@www ~]$ diff folder/file.html folder2/file.html

Standard Output

The #’s at the top are the line #’s, the means it is from the right file.

List Syntax
[test@www ~]$ diff -Bbrq folder folder2

List Output

This time I am listing all of the files in each directory that are different. Each parameter of diff (right after “-“) will change the output that it gives you.
-B = Ignore changes that just insert or delete blank lines.
-b = Ignore changes in amount of white space.
-r = When comparing directories, recursively compare any subdirectories found.
-q = Report only whether the files differ, not the details of the differences.

It not only shows you the files that are only in one directory, but it shows which files in each are different.

For more information on diff from a UNIX prompt, type: man diff

diff, differences, file system, man, manual, parameters, unix, unix commands

About the author

Timothy Haroutunian

Timothy Haroutunian is a ServiceNow Cloud Implementation Specialist at Acorio. ServiceNow is an IT Management solution that allows for a complete view of your IT and physical environment.

Permanent link to this article: http://www.armenianeagle.com/2006/09/18/unix-diff-command/


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.