Empulse Group a collection of notes from a sys admin, musician, and father


using ‘diff’ to compare files or directories

Find differences between two files or directories.



# diff sample1 sample2


< sample text. I

< will not forget


> EXTREMELY sample text. I

> will not EVER WANT




< Good bye,



# cat sample1

This is my

sample text. I

will not forget

to write another message,

for my friends.

Good bye,

and thanks for all the fish!



# cat sample2

This is my

EXTREMELY sample text. I

will not EVER WANT

to write another message,


for my friends.

and thanks for all the fish!





(line number of range) (c, a, or d) (line number of range)


'c' - stands for a change in the line

'a' - stands for append after the line

'd' - stands for delete the line



:: For side by side comparison:


# diff -y file1 file2


'|' - stands for a change between the lines

'>' - stands for an addition of text from file2 that was not in file1

'<' - stands for a deletion of text from file1 since not found in file2



:: To create a patch file from the diff:


# diff file1 file2 > patch



:: To patch the original file:


# patch file1 -i patch -o updatedfile


# if diff sample1 sample1; then echo "files are the same"; else echo "files are DIFFERENT"; fi

files are the same



:: To compare directories:


# ls tmp1

sample1 sample2


# ls tmp2

file1 file2 sample1


# diff tmp1 tmp2

Only in tmp2: file1

Only in tmp2: file2

Only in tmp1: sample2

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.

Copyright &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;copy; 2018 Empulse Group &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;middot; Powered by WordPress
Lightword Theme by Andrei Luca Go to top &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;uarr;