Find file differences linux

Given two directory trees, how can I find out which files differ by content? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

This outputs exactly what the differences are between corresponding files. I’m interested in just getting a list of corresponding files whose content differs. I assumed that this would simply be a matter of passing a command line option to diff , but I couldn’t find anything on the man page. Any suggestions?

With respect to one of the directories, how to get only the files/directories which are extra in the other?

10 Answers 10

diff --brief --recursive dir1/ dir2/ 

Or alternatively, with the short flags -qr :

If you also want to see differences for files that may not exist in either directory:

diff --brief --recursive --new-file dir1/ dir2/ # with long options diff -qrN dir1/ dir2/ # with short flag aliases 

Nice. But shorter is diff -qr dir1/ dir2/ and my extended version to diff -qr dir1/ dir2/ | grep ‘ differ’

@skv Not exactly what the original question asked, but updating the answer to accommodate this question as well.

@MikeMaxwell It needs to be —brief . -brief is interpreted as -b -r -i -e -f , in other words as a set of flags not as a single option.

@daboross: wow, I’ve been using Unix/Linux for a l o n g time, and I never realized there was that distinction between ‘—‘ and ‘-‘. (I don’t think ‘—‘ existed when I got started.) Thanks for the explanation!

— options are called «UNIX options» and — options are called «GNU long options» according to man ps . You should make every program accept long options if it uses any options, for this takes little extra work and helps beginners remember how to use the program. source: gnu.org/software/libc/manual/html_node/Getopt-Long-Options.html, also google.com/search?q=gnu+long+options

It is exactly the same as Mark’s 🙂 But his answer bothered me as it uses different types of flags, and it made me look twice. Using Mark’s more verbose flags it would be:

diff --brief --recursive dir1/ dir2/ 

I apologise for posting when the other answer is perfectly acceptable. Could not stop myself. working on being less pedantic.

Читайте также:  Astra linux цветовая схема

..so does it make sense tu put different answers with JUST a different flavour? IMHO no! Does it make sense tu combine both answers to one consistent answer? yes! 😉

Just a question; what does the q stand for? Is it an abbreviation of something? I can’t find any logic behind the q ..

@kramer65 — it is the same as «—brief», but I guess you wonder why q? Perhaps for quick? «-b» is taken by «ignore changes in the amount of white space» according to the man page.

@sobi3ch You are right, I apologise again. To my defence, I do not think I had the ability to edit the other answer at the time.

I like to use git diff —no-index dir1/ dir2/ , because it can show the differences in color (if you have that option set in your git config) and because it shows all of the differences in a long paged output using «less».

Neat. Who would’ve guessed that git can diff arbitrary directories, not just the repo against its files?

If you comparing (like me) 2 dirs as seperate git projects/repos then you need add —no-index more on stackoverflow.com/a/1792477/473390. I’ve updated @alan-porter answer.

I like this one, I also find that if you add —name-status to the command line, it will just show the file name list with «M/A/D» flags for Modified/Added/Deleted status.

It happens so that both directories are actually containing the .git folder, how can I exclude it from the compare?

rsync --dry-run --recursive --delete --links --checksum --verbose /dir1/ /dir2/ > dirdiff_2.txt # or same in short rsync -nrlcv --delete /dir/ > dirdiff_2.txt 
diff --brief --recursive --no-dereference --new-file --no-ignore-file-name-case /dir1 /dir2 > dirdiff_1.txt # or same in short diff -qrN --no-dereference --no-ignore-file-name-case /dir > dirdiff_1.txt 

They are functionally equivalent, but performance may vary depending on:

  • If the directories are on the same drive, rsync is faster.
  • If the directories reside on two separate drives, diff is faster.

This is because diff puts an almost equal load on both directories in parallel, maximizing load on the two drives. rsync calculates checksums in large chunks before actually comparing them. That groups the i/o operations in large chunks and leads to a more efficient processing when things take place on a single drive.

Источник

9 Best File Comparison and Difference (Diff) Tools for Linux

While writing program files or normal text files, programmers and writers sometimes want to know the difference between two files or two versions of the same file. When you compare two computer files on Linux, the difference between their contents is called a diff. This description was born out of a reference to the output of diff, the well known Unix command-line file comparison utility.

9 Best Linux File Diff or Comparison Tools

There are several file comparison tools that you can use on Linux, and in this review, we shall look at some of the best terminal based and GUI diff tools you can take advantage of while writing code or other text files.

Читайте также:  Linux dev dri card0

1. diff Command

I like to start with the original Unix command-line tool that shows you the difference between two computer files. Diff is simple and easy to use, it comes pre-installed on most Linux distributions. It compares files line by line and outputs the difference between them.

You can check out the manual entry for diff to easily use it.

Linux diff Command to Compare Files

There are some wrappers for the diff tool that enhance its functionality and these include:

colordiff Command

Colordiff is a Perl script that produces same output as diff, but with color and syntax highlighting. It has customizable color schemes.

You can install Colordiff on your Linux systems, using default package manager tools called yum, dnf or apt-get as shown.

# yum install colordiff [On CentOS/RHEL/Fedora] # dnf install colordiff [On Fedora 23+ version] $ sudo apt-get install colordiff [On Debian/Ubuntu/Mint]

You can check out the manual entry for Colordiff as shown.

Linux Colordiff Command - Color diff Output

wdiff Command

The wdiff utility is a front end to diff command used to compare files on a word by word basis. This program is very useful when comparing two texts for changed words and for which paragraphs have been refilled.

To install wdiff on your Linux systems, run:

# yum install wdiff [On CentOS/RHEL/Fedora] # dnf install wdiff [On Fedora 23+ version] $ sudo apt-get install wdiff [On Debian/Ubuntu/Mint]

Use wdiff manual for how to use it on Linux.

wdiff Compare Two Files in Linux

2. Vimdiff Command

Vimdiff works in an advanced manner in comparison to diff utility. It enables a user to edit up to four versions of a file while showing their differences. When you run it, Vimdiff opens two or three or four files using vim text editor.

Vimdiff Edit Multiple Files for Differences

Having looked the old school diff tools, lets quickly move to some GUI diff tools available on Linux.

3. Kompare

Kompare is a diff GUI wrapper that allows users to view differences between files and also merge them.

Some of its features include:

Kompare Tool - Compare Two Files in Linux

  1. Supports multiple diff formats
  2. Supports comparison of directories
  3. Supports reading diff files
  4. Customizable interface
  5. Creating and applying patches to source files

4. DiffMerge

DiffMerge is a cross-platform GUI application for comparing and merging files. It has two functionality engines, the Diff engine which shows the difference between two files, which supports intra-line highlighting and editing and a Merge engine which outputs the changed lines between three files.

It has got the following features:

DiffMerge - Compare Files in Linux

  1. Supports directory comparison
  2. File browser integration
  3. Highly configurable

5. Meld – Diff Tool

Meld is a lightweight GUI diff and merge tool. It enables users to compare files, directories plus version controlled programs. Built specifically for developers, it comes with the following features:

Meld - A Diff Tool to Compare File in Linux

  1. Two-way and three-way comparison of files and directories
  2. Update of file comparison as a users types more words
  3. Makes merges easier using auto-merge mode and actions on changed blocks
  4. Easy comparisons using visualizations
  5. Supports Git, Mercurial, Subversion, Bazaar plus many more
Читайте также:  Linux where to get it

6. Diffuse – GUI Diff Tool

Diffuse is another popular, free, small and simple GUI diff and merge tool that you can use on Linux. Written in Python, It offers two major functionalities, that is: file comparison and version control, allowing file editing, merging of files and also output the difference between files.

You can view a comparison summary, select lines of text in files using a mouse pointer, match lines in adjacent files and edit different file. Other features include:

DiffUse - A Tool to Compare Text Files in Linux

  1. Syntax highlighting
  2. Keyboard shortcuts for easy navigation
  3. Supports unlimited undo
  4. Unicode support
  5. Supports Git, CVS, Darcs, Mercurial, RCS, Subversion, SVK and Monotone

7. XXdiff – Diff and Merge Tool

XXdiff is a free, powerful file and directory comparator and merge tool that runs on Unix like operating systems such as Linux, Solaris, HP/UX, IRIX, DEC Tru64. One limitation of XXdiff is its lack of support for unicode files and inline editing of diff files.

It has the following list of features:

xxdiff Tool

  1. Shallow and recursive comparison of two, three file or two directories
  2. Horizontal difference highlighting
  3. Interactive merging of files and saving of resulting output
  4. Supports merge reviews/policing
  5. Supports external diff tools such as GNU diff, SIG diff, Cleareddiff and many more
  6. Extensible using scripts
  7. Fully customizable using resource file plus many other minor features

8. KDiff3 – – Diff and Merge Tool

KDiff3 is yet another cool, cross-platform diff and merge tool made from KDevelop. It works on all Unix-like platforms including Linux and Mac OS X, Windows.

It can compare or merge two to three files or directories and has the following notable features:

KDiff3 Tool for Linux

  1. Indicates differences line by line and character by character
  2. Supports auto-merge
  3. In-built editor to deal with merge-conflicts
  4. Supports Unicode, UTF-8 and many other codecs
  5. Allows printing of differences
  6. Windows explorer integration support
  7. Also supports auto-detection via byte-order-mark “BOM”
  8. Supports manual alignment of lines
  9. Intuitive GUI and many more

9. TkDiff

TkDiff is also a cross-platform, easy-to-use GUI wrapper for the Unix diff tool. It provides a side-by-side view of the differences between two input files. It can run on Linux, Windows and Mac OS X.

Additionally, it has some other exciting features including diff bookmarks, a graphical map of differences for easy and quick navigation plus many more.

Having read this review of some of the best file and directory comparator and merge tools, you probably want to try out some of them. These may not be the only diff tools available you can find on Linux, but they are known to offer some the best features, you may also want to let us know of any other diff tools out there that you have tested and think deserve to be mentioned among the best.

Источник

Оцените статью
Adblock
detector