Unix Diff
diff is a mightly command line tool found in most of Unix and Unix-like operating systems. diff helps you to find differences between files and directories.
Things You Can Do with Unix Diff
- Compare files with diff
- Compare directories with diff
- Compare binary files with diff
- Compare backup copies to current files
How To Use Unix Diff
In its simplest form, compares two text files – you provide their names as command line options.
Let’s create two files first:
Diff won’t show any difference because they’re exactly the same – empty new files:
If we change one of the files by adding the hello word to it, see what happens:
Diff spotted the difference and indicated, which file has it (> means second file, the file in the right section of the command line).
Now, let’s add something else to the first file to make things a bit more interesting:
See? diff now highlighted that the first file (< pointing to the file in the left part of the command line you specified) also has a line that’s different from second file.
If we now add exactly the same line to both files, diff will ignore it because it only shows what’s different:
That’s it for today! I’ll show you some advanced usages of the diff command some other time.
See Also
See Also
diff is a mightly command line tool found in most of Unix and Unix-like operating systems. diff helps you to find differences between files and directories.
Things You Can Do with Unix Diff
- Compare files with diff
- Compare directories with diff
- Compare binary files with diff
- Compare backup copies to current files
How To Use Unix Diff
In its simplest form, compares two text files – you provide their names as command line options.
Let’s create two files first:
Diff won’t show any difference because they’re exactly the same – empty new files:
If we change one of the files by adding the hello word to it, see what happens:
Diff spotted the difference and indicated, which file has it (> means second file, the file in the right section of the command line).
Now, let’s add something else to the first file to make things a bit more interesting:
See? diff now highlighted that the first file (< pointing to the file in the left part of the command line you specified) also has a line that’s different from second file.
If we now add exactly the same line to both files, diff will ignore it because it only shows what’s different:
That’s it for today! I’ll show you some advanced usages of the diff command some other time.