/ factorpad.com / tech / linux-essentials / diff-command.html
An ad-free and cookie-free website.
Beginner
Learn to compare text files at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux diff Command Summary with Examples (3:46)
Our thirty-fourth word, or command to memorize is
diff
from our category
Text.
diff
allows you to compare lines of
text files.
-options | description |
---|---|
--help |
Print help screen |
-y ,
--side-by-side |
Show output in two columns |
Recall from previous videos, we've been exploring text editing and
diff
is another useful skill here.
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s)
.
The diff
command has nearly
50 options, and the arguments are the files or
directories of files you'd like to compare.
Like most commands, help is available with double-dash
--help
. The
diff
command has so many options
because files often come with a variety of codes for ends of lines and
field delimiters for example. The -y
option allows you to visualize changes in two columns.
So why is diff
an important command?
Well, you might be in a situation where you need to validate edits,
backups and progress on a project.
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.
Here we go. Let's start by copying
video34.txt
to
video35.txt
.
Then edit video35.txt using nano
.
Recall, in video 16, we used the touch
command to change the date from the 10th to the 9th, let's change that
back to the 10th to make it accurate.
File video35.txt (before).
Ctrl-x
to close,
y
and
Enter
to save.
File video35.txt (after).
Next, let's do a diff -y
the
input file video34.txt
, the output
file video35.txt
.
Notice this mark here |
. That's
helpful.
And last, let's go optionless and interpret.
Think of the diff
command as saying
"what needs to be done to the input file to make it look like the
output file?" There are three possible letters,
a
for add,
c
for change, and
d
for delete. So this means, change
line 3 of the input file, to line 3 of the output file.
Okay now you know how to use diff
.
And you know the syntax for commands, options and arguments.
One last tip about the diff
command.
So with nearly 50 options, see the capabilities in the manual page, and
tune in for video 35.
Okay, thanks for visiting today. I hope this was a helpful
introduction to the diff
command.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
Three ways to stay in touch, 1) subscribe on YouTube, 2) follow @factorpad on Twitter and 3) join our no-spam email list.
cut
command,
hit Back.comm
, click Next./ factorpad.com / tech / linux-essentials / diff-command.html
A newly-updated free resource. Connect and refer a friend today.