Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App

diff3 command in Linux with examples

Last Updated : 15 May, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
diff3 command is used to compare the three files line by line. It internally uses the diff command to compare. When three files are compared then the following output may come which have their own meaning:
  • ==== : It means all the files are different.
  • ====1 : File 1 is different.
  • ====2 : File 2 is different.
  • ====3 : File 3 is different.
Syntax:
diff3 [OPTIONS]
Example: Let us consider three files as a.txt, b.txt and c.txt. Now if diff3 command is used over these three files then following output will come: Here, the very first line ‘====3’ tells that the file number 3 i.e. c.txt is different from the other two. This is visible in the output too. Options:
  • 'c' signifies change while ‘a’ signifies append : 'c' signifies ‘change’ required in the lines/text. If the alphabet ‘a’ appears then it signifies a line needs to be appended. Example: Now if diff3 command is used over these three files : The output above signifies that the change in file3 (i.e c.txt) needs to be appended in file1 (a.txt) and file2 (b.txt) to make all the three file similar. Alternatively, the second line in b.txt can be changed(c) to make all the three files similar.
  • -x : It produces an editor script of only those changes where all three files differ. Example: Apply diff3 -x The output says that the third line of a.txt has to changed to ‘mahi’ in order to merge the changes that would turn b.txt to c.txt.
  • diff3 -X : It is similar to -x except that it also checks for overlapping ranges of lines in the changes. diff3 highlights these ranges in the output. Example: Apply diff3 -X
  • diff3 -e : It can be used to output non merged changes from b.txt to c.txt into a.txt. Example: Apply diff3 -e So we see that the output shows the non merged changes.
  • diff3 -E : It also checks for overlapping ranges of lines in the changes. diff3 highlights these ranges in the output. Example: Apply diff3 -E
  • diff3 -m : A merged file comprising of contents from all the three files can be produced using the -m option. Example: Applying diff3 -m So the above output shows contents of the merged file that has merged contents from all the three files supplied as arguments to diff3.
  • diff3 '-' : Accept one argument from stdin using '-'. A '-' can be used in place of any one of the file names to accept input from stdin for that argument. Example: Output: As we can see, when the command above was run, the content of third file was given through stdin. Note that after entering the contents of file from stdin, one needs to press the key combination ctrl+d to get the output of diff3.
  • diff3 -a : To compare even non text files, an option -a can be used that tells diff3 to consider all input files as text files. Example: So the output above shows that diff3 tried to compare even an odt file treating it as a text file.

M

mahimabadjate
Improve
Article Tags :
  • Linux-Unix

Similar Reads

    ctags command in Linux with examples
    The ctags command in Linux is commonly used with classic editors such as vi or vim to create an index or tags file for source code. This allows quick navigation across files, enabling users to jump to function definitions or references. ctags generates a cross-reference file that lists various sourc
    3 min read
    cupsd command in Linux with examples
    cupsd is a type of scheduler for CUPS (Common Unit Printing System). It implements the printing system on the basis of the Internet Printing Protocol(Version 2.1). If no options is being specified on the command-line then the default configuration file /etc/cups/cupsd.conf will be automatically be u
    3 min read
    curl Command in Linux with Examples
    curl is a command-line utility for transferring data to or from a server, employing a range of internet protocols such as HTTP, HTTPS, FTP, SCP, and SFTP.Whether you want to download a file, test a REST API, or simply verify that a website is up and running, curl is your best friend. It is accessed
    5 min read
    cut command in Linux with examples
    The cut command in linux is a command for cutting out the sections from each line of files and writing the result to standard output. It can be used to cut parts of a line by byte position, character, and field. The cut command slices a line and extracts the text. It is necessary to specify an optio
    8 min read
    cvs command in Linux with Examples
    In today's digital era, where file modifications and version control are essential, the Concurrent Versions System (CVS) command in Linux emerges as a powerful tool. CVS allows users to store and track the history of files, enabling easy retrieval of previous versions and restoring corrupted files.
    6 min read
    How to Display and Set Date and Time in Linux | date Command
    Unlock the full potential of the date command in Linux—a versatile tool that does more than just show the current date and time. With this command, you can set your system’s clock, synchronize time across networks, and even calculate past or future dates for tasks like scheduling or logging. In this
    8 min read
    dc command in Linux with examples
    The dc command is a versatile calculator found in Linux systems, operating using reverse Polish notation (RPN). This command allows users to perform arithmetic calculations and manipulate a stack, making it ideal for complex mathematical tasks directly from the command line.SyntaxThe basic syntax fo
    3 min read
    'dd' Command in Linux: Explained
    The dd command in Linux is a powerful utility for low-level data copying and conversion, primarily used for disk cloning, creating disk images, partition backups, and writing ISO files to USB drives. Mastering the dd command is essential for Linux system administrators, as it enables precise control
    6 min read
    declare command in Linux with Examples
    The built-in is a powerful built-in feature of the Bash shell. It allows users to declare and set attributes for variables and functions, enabling better control over their behavior. By understanding how to use declare, you can manage variables and functions more effectively in your shell scripts. T
    2 min read
    depmod command in Linux with examples
    depmod(Dependency Modules) command is used to generate a list of dependency description of kernel modules and its associated map files. This analyzes the kernel modules in the directory /lib/modules/kernel-release and creates a "Makefile"-like dependency file named modules.dep based on the symbols p
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences