Book Image

Linux Shell Scripting Essentials

By : Sinny Kumari, Khem Raj
Book Image

Linux Shell Scripting Essentials

By: Sinny Kumari, Khem Raj

Overview of this book

Table of Contents (15 chapters)
Linux Shell Scripting Essentials
About the Author
About the Reviewers

Comparing files

A comparison between two similar files makes sense in order to know what differences exist between the two files. For example, comparing the results obtained by a command ran on two sets of data. Another example can be comparing an older and a newer version of a shell script file in order to know what modifications have been made in script. Shell provides the diff command for file comparison.

Files comparison using diff

The diff command is used to compare files line by line. The syntax of using the diff command is as follows:

diff [option] file1 file2

Where, file1 and file2 are the files to be compared.

The options of the diff command are explained in the following table:




Only print if files differ


Print a message on stdout if the two files are identical


Display the diff results side by side


Do case-insensitive comparison of the files' content


Ignore changes in the number of whitespace

-u NUM

Output NUM (default 3)...