Learn to compare text files at the Linux command line.
Linux diff command summary with examples (3:46)
Videos can also be accessed from the YouTube Playlist.
Our thirty-fourth word, or command to memorize is
diff from our category
diff allows you to compare lines of
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).
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
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
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
Then edit video35.txt using
Recall, in video 16, we used the
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,
Enter to save.
File video35.txt (after).
Next, let's do a
diff -y the
video34.txt, the output
Notice this mark here
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
And you know the syntax for commands, options and arguments.
One last tip about the
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
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
If you like the videos as well, subscribe to the YouTube Channel here.
cutcommand, hit Back.
comm, click Next.