Subscribe
Home Craft How to Use diff to Compare Text Files in the Linux Terminal

How to Use diff to Compare Text Files in the Linux Terminal

by Staff
0 comment

diff is a standard command-line Linux utility that lets you compare the differences between two files. Here’s how you can use it to your advantage.


Have you ever had two similar files and wondered which parts are different? Are you writing code and trying to figure out how to blend in changes that you or some other programmer made? There’s a standard Linux utility called “diff” that will help.


What Is diff?

diff is a utility that shows the differences between two text files, which is where the name comes from. It’s part of the POSIX standard, which means that it’s present on nearly all Unix-like systems, including Linux as well as macOS and the other BSDs.

If you’re on a major Linux distribution, you’ll most likely have the GNU version. If you’re on a minimal Linux distro, you might have it as part of the BusyBox or Toybox library or the BSD version if you’re on a BSD system. You can see which version you have by checking the manual page:

man diff

Comparing Two Files on Linux With diff

To compare two text files, simply pass their path as arguments to diff:

diff file1 file2

diff will show the lines that are different between the two in the file. Lines in the first file are prefaced with a “<” and lines in the second are preceded with a “>” character. The output displays changed, appended, or deleted lines, including the number of lines affected overall.

If you change the first line, diff will output “1c1“, which means “start at line 1, change line 1.” In diff, “a” stands for “append“, “c” for “change” and “d” for “delete.”

Other diff Features and Options

To see files side-by-side, use the -y option:

diff -y file1 file2

The -u option produces a “unified” outlook with an editing script for the ed editor so that changes can be performed automatically.

Before distributed version control systems like Git were widely used, open-source projects would solicit patches in this format by email and then apply them to the codebase with the patch program.

Now You Can Compare Files on Linux With diff

The diff utility may seem obscure, but it’s beneficial to see the differences between two files, whether you’re simply comparing the files or submitting patches to an open-source developer.

If you’re not a fan of the Linux terminal, you don’t even have to use the command line to compare files, or even use your local machine at all. There are online tools that will let you compare files on the web.



Read the full article here

SaleBestseller No. 1
Apple AirPods Max Wireless Over-Ear Headphones. Active Noise Cancelling, Transparency Mode, Spatial Audio, Digital Crown for Volume Control. Bluetooth Headphones for iPhone - Green
Apple AirPods Max Wireless Over-Ear Headphones. Active Noise Cancelling, Transparency Mode, Spatial Audio, Digital Crown for Volume Control. Bluetooth Headphones for iPhone - Green
 Apple-designed dynamic driver provides high-fidelity audio; Active Noise Cancellation blocks outside noise, so you can immerse yourself in music
$449.99
SaleBestseller No. 3
Apple iPad Air 2, 64 GB, Space Gray (Renewed)
Apple iPad Air 2, 64 GB, Space Gray (Renewed)
Apple iOS 8; 9.7-Inch Retina Display; 2048x1536 Resolution; A8X Chip with 64-bit Architecture; M8 Motion Coprocessor
$129.99
SaleBestseller No. 4
2021 Apple 10.2-inch iPad (Wi-Fi, 64GB) - Silver
2021 Apple 10.2-inch iPad (Wi-Fi, 64GB) - Silver
Gorgeous 10.2-inch Retina display with True Tone; A13 Bionic chip with Neural Engine; 8MP Wide back camera, 12MP Ultra Wide front camera with Center Stage
$269.99
Bestseller No. 5
2022 Apple TV 4K Wi‑Fi with 64GB Storage (3rd Generation)
2022 Apple TV 4K Wi‑Fi with 64GB Storage (3rd Generation)
4K Dolby Vision and HDR10+ for vivid picture quality; Dolby Atmos for three-dimensional, theater-like sound
$123.49
Bestseller No. 7
Apple AirTag 4 Pack
Apple AirTag 4 Pack
Keep track of and find your items alongside friends and devices in the Find My app; Simple one-tap setup instantly connects AirTag with your iPhone or iPad
Bestseller No. 8
Apple MacBook Air with Intel Core i5, 1.6GHz, (13-inch, 4GB,128GB SSD) - Silver (Renewed)
Apple MacBook Air with Intel Core i5, 1.6GHz, (13-inch, 4GB,128GB SSD) - Silver (Renewed)
1.6 GHz dual-core Intel Core i5 (Turbo Boost up to 2.7 GHz) with 3 MB shared L3 cache; 13.3-Inch (diagonal) LED-backlit Glossy Widescreen Display, 1440 x 900 resolution
$305.00
Bestseller No. 9
Apple Of My Eye
Apple Of My Eye
Amazon Prime Video (Video on Demand); Amy Smart, Burt Reynolds, Liam McIntyre (Actors); Castille Landon (Director) - Castille Landon (Writer) - Dori A. Rath (Producer)
$3.99
SaleBestseller No. 10
Apple 35W Dual USB-C Port Compact Power Adapter ​​​​​​​
Apple 35W Dual USB-C Port Compact Power Adapter ​​​​​​​
The compact size and folding prongs make it easy to pack and store.; Charging cable sold separately.
$52.00

You may also like

Leave a Comment

Iman Hearts is one of the biggest lifestyle news and articles portals, we provide the latest news and articles about family, lifestyle, entertainment, and many more, follow us to get the latest news about what matters to you.

 

© 2022 Iman Hearts. All rights reserved. Sitemap