Questions tagged [diff]
diff - Command-line tool to display the differences between two files, or each corresponding file in two directories.
527
questions
198
votes
5
answers
267k
views
Understanding of diff output
I have file1.txt
this is the original text
line2
line3
line4
happy hacking !
and file2.txt
this is the original text
line2
line4
happy hacking !
GNU is not UNIX
if I do: diff ...
172
votes
15
answers
102k
views
diff within a line
I have some sql dumps that I am looking at the differences between. diff can obviously show me the difference between two lines, but I'm driving myself nuts trying to find which values in the long ...
161
votes
1
answer
87k
views
What's the recommended way of copying changes with vimdiff?
When comparing files, and updating a source code repository, I like to use vimdiff. To copy changes made from one file to the other, I usually use a key sequence like this:-
Shift + V (select line)
k ...
112
votes
4
answers
71k
views
Can't pipe into diff?
I wanted to be clever and compare a remote file to a local file without first manually downloading it. I can get the contents of the remote file by
ssh user@remote-host "cat path/file.name"
However,...
88
votes
5
answers
173k
views
Comparing two files in Vim
Is it possible to view two files side-by-side in Vim? If so, how can I set up my editor to do this, and is there a way to diff between the two files within Vim?
I am aware of the :next and :prev ...
80
votes
15
answers
89k
views
How to color diff output?
I wanted to format the Unix files conditionally, I am currently working on diff command and wanted to know if it is possible to format the text of the diff command output.
Example:
Matched ...
78
votes
10
answers
58k
views
Converting colored output into html
There are tools providing coloured output:
dwdiff -c File1 File2 # word level diff
grep --color=always # we all know this guy
...
The question is: How to convert their colored output of arbitrary ...
66
votes
6
answers
89k
views
How to diff files ignoring comments (lines starting with #)?
I've two configuration files, the original from the package manager and a customized one modified by myself. I've added some comments to describe behavior.
How can I run diff on the configuration ...
65
votes
3
answers
209k
views
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, ...
59
votes
6
answers
55k
views
Is there a condensed side-by-side diff format?
I have two log files with thousands of lines. After pre-processing, only some lines differ. These remaining lines are either real differences, or shuffled groups of lines.
Unified diffs allow me to ...
54
votes
5
answers
65k
views
Run a diff between local and remote files
I'm connected on a host via ssh and I'd like to compare (let's say with diff) a certain config file against its counterpart on an another host, also accessible via ssh, without having to manually ...
50
votes
1
answer
20k
views
Make diff Use Full Terminal Width in Side-by-Side Mode
Most applications are smart about using the full width of the terminal available to them. My shell does, screen, vim, etc. However, diff in side-by-side mode (-y), does not. This angers me. It uses ...
49
votes
4
answers
69k
views
Diffing two big text files
I have two big files (6GB each). They are unsorted, with linefeeds (\n) as separators. How can I diff them? It should take under 24h.
48
votes
2
answers
37k
views
How do I diff the outputs of two commands? [duplicate]
How can I use the diff command to compare 2 commands' outputs?
Does something like this exist?
diff ($cat /etc/passwd) ($cut -f2/etc/passwd)
47
votes
7
answers
78k
views
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 ...
46
votes
2
answers
106k
views
Common lines between two files [duplicate]
I have the following code that I run on my Terminal.
LC_ALL=C && grep -F -f genename2.txt hg38.hgnc.bed > hg38.hgnc.goi.bed
This doesn't give me the common lines between the two files. ...
46
votes
4
answers
19k
views
How do I pipe colored diff output to less?
I've been using git diff, which produces colored output. However, I now find I need to use ordinary diff for something, and it's producing a lot of output that is hard to read because of the lack of ...
44
votes
1
answer
43k
views
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
| `-...
42
votes
6
answers
70k
views
How to fix "Hunk #1 FAILED at 1 (different line endings)" message?
I am trying to create a patch with the command
git diff sourcefile >/var/lib/laymab/overlay/category/ebuild/files/thepatch.patch
when I apply the patch, it gives me
$ patch -v
GNU patch 2.7.5
$...
40
votes
5
answers
52k
views
Output the common lines (similarities) of two text files (the opposite of diff)?
Diff is a great tool to display the changes between two files. But how to display the similarities of two text files (while ignoring the differences)?
I.e. sample input:
a:
Foo Bar
X
Hello
World
42
...
40
votes
10
answers
22k
views
Compare directories but not content of files
With
diff -r
I can do this task, however it takes so long because diff checks file's content.
I want something that determine that two files are the same regarding of their size, last modified, etc. ...
38
votes
3
answers
40k
views
diff where lines are mostly the same but out of order?
I want to diff two sets of mod_rewrite rules. The set of lines are about 90% identical, but the order is so different that diff basically says they are completely different.
How can I see which lines ...
35
votes
3
answers
28k
views
Diff, show modified line from right file only
I have file a and b and I would like to output lines of b that changed since it was cloned from a. Just the modified lines, no surrounding context, no diff offset marks.
How can I do that using shell ...
30
votes
4
answers
8k
views
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:
[...
30
votes
7
answers
35k
views
Which GUI diff viewer would you recommend, with Copy-to-Left/Right functionality?
I've hardly ever used anything other than Meld. Can you recommend anything else?
It would be extra nice if you give a reason for your recommendation (as a Comment).
[note] I want an alternative ...
29
votes
2
answers
42k
views
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 ...
29
votes
4
answers
18k
views
Get diff changes between original files installed with apt and current files
I installed php5-fpm package using apt; then I made some changes to the PHP configuration files.
Now I would get the diffs between the original files versions (the ones of the package installed) and ...
28
votes
2
answers
33k
views
Is this a good way to create a patch?
I would like to create a patch from a specific gcc branch comparing it to the official releases; so when I unpack the tarball from the stable release, I can apply the patch and get the equivalent of ...
27
votes
5
answers
35k
views
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 ...
25
votes
8
answers
41k
views
how to use patch and diff to merge two files and automatically resolve conflicts
I have read about diff and patch but I can't figure out how to apply what I need.
I guess its pretty simple, so to show my problem take these two files:
a.xml
<resources>
<color name="...
24
votes
5
answers
36k
views
How do you compare two folders and copy the difference to a third folder?
You've got three folders:
folder current, which contains your current files
folder old, which contains an older version of the same files
folder difference, which is just an empty folder
How do you ...
23
votes
1
answer
2k
views
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 ...
23
votes
3
answers
5k
views
Display only relevant hunks of a diff/patch based on a regexp
git log -G<regex> -p is a wonderful tool to search a codebase's history for changes that match the specified pattern. However, it can be overwhelming to locate the relevant hunk in the diff/...
22
votes
5
answers
3k
views
Why use diff/patch when it is easier to just use cp
diff -u file1.txt file2.txt > patchfile
creates a patch file which consists of instruction for patch to convert file1.txt to be exactly like file2.txt
Can't this be done using cp command instead? ...
22
votes
4
answers
67k
views
How to write the difference between two files into a file
Saying that I have two files: a.txt and b.txt.
The content of a.txt:
hello world
The content of b.txt:
hello world
something else
Of course I can use vimdiff to check their difference, I can make ...
22
votes
2
answers
26k
views
Using the diff command to compare two strings?
According to https://www.computerhope.com/unix/udiff.htm
The diff command analyzes two files and prints the lines that are
different.
Can I use the same diff command to compare two strings?
$ more ...
22
votes
3
answers
20k
views
Can rsync update a large file that has only changed partially without full retransmission?
I'm making a minor change to a very large file image file (just a few pixels difference) which takes a long time to transfer over the network.
Is there a way for rsync to identify the difference in ...
22
votes
3
answers
9k
views
Is there a Linux deep diff tool that also compares file attributes?
Is there a Linux tool like diff that will recursively compare files and directories, but with the addition of also comparing: extended attributes, acl's, se contexts?
21
votes
2
answers
2k
views
How do I save the changes to my vim buffer as a patch file?
Is there a way to save the changes I made to my vim buffer as a patch file for the original file, without saving it as a separate file and using diff?
20
votes
3
answers
6k
views
Git pager is less, but what is causing the output coloring?
less itself isn't capable of doing syntax highlighting, according to this thread.
However, git diff nicely shows colored output in less, its default pager. When I redirect the output of git diff ...
20
votes
4
answers
10k
views
Comparing directories in Emacs
I am experimenting with ediff-directories, but I am not sure I am using it correctly.
I read in the documentation that, once I supply two directories to ediff-directories, if I press == Emacs ...
19
votes
2
answers
14k
views
Tool in unix to subtract text files?
I have a large file composed of text fields separated by semicolons in the form of a large table. It has been sorted.
I have a smaller file composed of the same text fields. At some point, someone ...
19
votes
5
answers
1k
views
rolling diffs for storage of highly similar files?
At work we do a nightly dump of our mysql databases. From day to day, I would guestimate that close to 90-95% of the data is duplicate, increasing as time goes on. ( Heck at this point some are ...
18
votes
4
answers
26k
views
Diff several files, true if all not equal
I have a number of files, I want to check that all those files have the same content.
What command line could I use to check that?
Usage could be something like:
$ diffseveral file1 file2 file3 ...
18
votes
4
answers
19k
views
Can I get the opposite of `diff -q` -- matching identical files without printing their contents
I have a number of files in a directory, and I want to check that they are all unique. For simplicity, let's say I have three files: foo.txt, bar.txt and baz.txt. If I run this loop, I will check them ...
18
votes
3
answers
27k
views
What does 'patch unexpectedly ends in middle of line' mean?
This is the output of my patch command:
Hunk #11 merged at 4184,4190.
Hunk #12 merged at 4444.
Hunk #13 merged at 4944.
Hunk #14 NOT MERGED at 5106-5116.
Hunk #15 merged at 5290.
Hunk #16 merged at ...
18
votes
4
answers
20k
views
Compare massive directories with progress report
I just rsync-ed 2,000,000 files (3TB) from one RAID to another.
I want to make sure my data is intact.
rsync -c takes a really long time.
diff doesn't show me what it's doing.
Is there an ...
17
votes
1
answer
61k
views
Can’t find file to patch at input line 3 [duplicate]
I generated a patch using the diff command with the number of context lines as 1 (-c option). My patch file contents:
*** /home/sk/abc/def/src/klm/a.py 2015-05-18 16:25:50.348398554 +0530
--- /opt/...
16
votes
5
answers
12k
views
Diff of two similar big raw binary files
Let's say I have a 4 GB file abc on my local computer. I have uploaded it to a distant server via SFTP, it took a few hours.
Now I have slightly modified the file (probably 50 MB maximum, but not ...
16
votes
3
answers
5k
views
How do I do an N-way diff?
How do I diff the output of multiple commands? vimdiff can support up to four files, but diff itself seems to support exactly two files.
Is it directly possible with some variant of diff, or do I ...