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

15May/110

using ‘diff’ to compare files or directories

Find differences between two files or directories.

 

 

# diff sample1 sample2

2,3c2,3

< sample text. I

< will not forget

---

> EXTREMELY sample text. I

> will not EVER WANT

4a5

> OR BE BAD

6d6

< 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,

OR BE BAD

for my friends.

and thanks for all the fish!

 

 

Explanation:

 

(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.