UNIX Commands: - R. Seetha Rama Guptha
UNIX Commands: - R. Seetha Rama Guptha
Option Description
-1 Suppress the output column of lines unique to file1.
-2 Suppress the output column of lines unique to file2.
-3 Suppress the output column of lines duplicated in
file1 and file2.
Example
$ comm file1.txt file2.txt
apple FILE1.TXT FILE2.TXT
ball
cat apple ball
doll ball cat
elephant cat fox
fox doll gun
gun elephant house
house
Example
$ comm -1 -2 file1.txt file2.txt
ball FILE1.TXT FILE2.TXT
cat
apple ball
ball cat
cat fox
doll gun
elephant house
The cmp Command
Compares two files and tells you which line
numbers are different.
cmp[-c][-i N][-l][-n N] file1 file2
Option Description
-c Output differing bytes as characters.
-i N Ignore differences in the first N bytes of input.
-l Write the byte number (decimal) and the differing
bytes (octal) for each difference.
-n N Compare at most N bytes.
Example
$ cmp file1.txt file2.txt
file1.txt file2.txt differ: byte 8, line 2
FILE1.TXT FILE2.TXT
apple apple
ball bell
cat cap
Example
$ cmp -c file1.txt file2.txt
file1.txt file2.txt differ: byte 8, line 2 is 141 a 145 e
FILE1.TXT FILE2.TXT
apple apple
ball bell
cat cap
Example
$ cmp -i 6 file1.txt file2.txt
file1.txt file2.txt differ: byte 2, line 1
FILE1.TXT FILE2.TXT
apple apple
ball bell
cat cap
Example
$ cmp -n 10 file1.txt file2.txt
file1.txt file2.txt differ: byte 8, line 2
FILE1.TXT FILE2.TXT
apple apple
ball bell
cat cap
Example
$ cmp -l file1.txt file2.txt
8 141 145
14 164 160
FILE1.TXT FILE2.TXT
apple apple
ball bell
cat cap
The diff Command
Displays two files and prints the lines that are
different.
diff[-i][-c][-w][-e][-h][-l][-r]
[-s][-S name] file1 file2
The diff Command
Option Description
-i Ignore Case.
-c Produces a listing of differences with three lines of context.
-w Ignores spaces and tabs.
-e Produces a script of only a, c, and d commands .
-h It works only when changed stretches are short and well
separated.
-l Produce output in long format.
-r Applies diff recursively to common subdirectories encountered.
-s Reports files that are the identical; these would not otherwise
be mentioned.
-S name Starts a directory diff in the middle, beginning with the file
name.
Example
$ diff -i file1.txt file2.txt
1d0
< alligator
3c2
< cat File1.Txt File2.Txt
---
>ct alligator Bull
5c4 bull ct
< elephant
--- cat doll
> elephant doll elephant
7a7 elephant fox
> hyena
fox giraffe
giraffe hyena
Example
$ diff -i -w file1.txt file2.txt
1d0
< alligator
3c2
< cat File1.Txt File2.Txt
---
>ct alligator Bull
7a7 bull ct
> hyena
cat doll
doll elephant
elephant fox
fox giraffe
giraffe hyena
Example
$ diff -c -i file1.txt file2.txt
*** 1,7 ****
- alligator
bull
! cat
doll
! elephant File1.Txt File2.Txt
fox
giraffe alligator Bull
--- 1,7 ---- bull ct
Bull cat doll
!ct
doll doll elephant
! elephant elephant fox
fox
giraffe fox giraffe
+ hyena giraffe hyena
Example
$ diff -e -i file1.txt file2.txt
7a
hyena
.
5c
elephant File1.Txt File2.Txt
. alligator Bull
3c
ct bull ct
. cat doll
1d doll elephant
elephant fox
fox giraffe
giraffe hyena
Example
$ diff dir1 dir2
Only in dir1: file2.txt
Only in dir1: file3.txt
DIR1 DIR2
file1.txt file1.txt
file2.txt
file3.txt
Example
$ diff -s dir1 dir2
Files dir1/file1.txt and dir2/file1.txt are identical
Only in dir1: file2.txt
Only in dir1: file3.txt
DIR1 DIR2
file1.txt file1.txt
file2.txt
file3.txt
Example
$ diff -S file3.txt dir1 dir2
Only in dir1: file3.txt
DIR1 DIR2
file1.txt file1.txt
file2.txt
file3.txt
The spell Command
Select or reject lines common to two files.
Spell filename
File1.Txt
The common use for Notepad is to edit text (.txt) files
$ Spell file1.txt
txt
The find Command
Search for a file based on a criteria