diff - Command-line tool to display the differences between two files, or each corresponding file in two directories.
Questions tagged [diff]
545 questions
73
votes
3 answers
Recursively compare two directories with diff -r without output on broken links
I am using diff -r a b to recursively compare directories a and b. It often happens though that there are some broken links (the same broken links in both a and b directories and pointing to the same, non-existing targets).
diff then outputs error…

Marcus Junius Brutus
- 4,587
- 11
- 44
- 65
50
votes
1 answer
How does "diff --exclude" work?
I'm trying to use diff to compare two directory trees while ignoring certain sub-directories, but I cannot get it to work. This is what my file structure looks like:
temp/
|-- d1/
| |-- f1.txt
| `-- ignoreme/
| `-- f2.txt
`-- d2/
|--…

d512
- 641
48
votes
7 answers
diff reports two files differ, although they are the same!
I have two files which look identical to me (including trailing whitespaces and newlines) but diff still says they differ. Even when I do a diff -y side by side comparison the lines look exactly the same. The output from diff is the whole 2…

DewinDell
- 745
31
votes
4 answers
Result of diff two files with switched lines says missing the same line twice
I am trying to understand the linux diff command on two files whose lines are just permutation of each other but not able to grok the output that it generates. Consider the three commands below:
[myPrompt]$ cat file1
apples
oranges
[myPrompt]$ cat…

Geek
- 6,688
30
votes
2 answers
diff - output line-numbers
I want to use cli tool for file comparison and need line-number before output line with which help I could jump to line difference, because I use tool which understands where to jump, if the line begins like this :line-number: regular line…

zetah
- 2,057
29
votes
5 answers
Compare two zip files for differences
diff command compares to see any difference betwenn two files. Can the same be used to compare two zip files, i.e if there is any difference in data ,like counts etc in individual files in the zipped files?

UnixPhile
- 391
23
votes
1 answer
What effect does the "-d" option have with diff?
The diff implementation on OpenBSD has a non-standard -d option with the following documentation:
-d
Try very hard to produce a diff as small as possible. This may
consume a lot of processing power and memory when processing
…

Kusalananda
- 333,661
14
votes
3 answers
diff reports the same line as different in 2 files
I have 2 files containing a list of songs.
hdsongs.txt and sdsongs.txt
I wrote a simple script to list all songs and output to text files, to then run a diff against.
It works fine for the most part, but the actual diff command in the script is…

user1718443
- 143
10
votes
5 answers
Diff head of files
I have two files. One file, I suspect, is a subset of the other. Is there a way to diff the files to identify (in a succinct manner) where in the first file the second file fits?

Richard
- 1,381
10
votes
3 answers
Side by side diff of large files
I have two ~1 GB files that I want to do a side by side diff of. Solutions I have tried:
diff - Works quickly but doesn't output side-by-side.
diff -y or sdiff - This outputs side-by-side but it outputs the entire file - not just the changes, so…

Timmmm
- 586
- 5
- 17
10
votes
2 answers
Diff: only compare if file exists, not contents
I want to use Diff only to check if files and directories exist the same in two locations but NOT compare the contents of the files themselves, because that's all I need and a regular Diff just takes too long for the amount of data. How would I go…

morph
- 121
10
votes
2 answers
How to show names of files being compared?
I used diff --from-file to compare my Riak dev1 config to the three others.
diff --from-file ~/riak/dev/dev1/etc/app.config \
~/riak/dev/dev2/etc/app.config \
~/riak/dev/dev3/etc/app.config \
~/riak/dev/dev4/etc/app.config
It shows the configs…
9
votes
2 answers
What does -u of diff really do?
Looks like -u can take an extra number argument, but I don't quiet get the manual,
It says,
-u, -U NUM, --unified[=NUM]
output NUM (default 3) lines of unified context
Someone name an example please?
I couldn't find a working one.

daisy
- 54,555
9
votes
3 answers
What does an exclamation mark mean in diff output?
I have an assignment for school. One part of it is to check a file for changes and write these changes to a log file. So far I've found the diff command which could be helpful in my opinion. Let's say I have two files with content like…

Denco
- 101
9
votes
2 answers
What do the numbers in the "@@" line mean in output of diff?
Here is an example of Unix Shell program diff, from Version Control with Git, by Loeliger, 2ed:
Let’s look at the diff in detail.
In the header, the original file is denoted by - - - and the new file
by +++.
The @@ line provides line number…

Tim
- 101,790