Book Image

Linux Shell Scripting Essentials

Book Image

Linux Shell Scripting Essentials

Overview of this book

Table of Contents (15 chapters)
Linux Shell Scripting Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

Option

Description

-q

Only print if files differ

-s

Print a message on stdout if the two files are identical

-y

Display the diff results side by side

-i

Do case-insensitive comparison of the files' content

-b

Ignore changes in the number of whitespace

-u NUM

Output NUM (default 3)...