• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Source Digit

Source Digit

Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • How To
  • Ubuntu
  • Instagram
  • Blogging
  • Android
  • WordPress
  • +More
    • Cloud Computing
    • Gadgets
    • Social Media
    • Technology
  • Write for Us
Home / How To / How To Compare Two Directories In Linux Recursively

How To Compare Two Directories In Linux Recursively

By Sourabh / October 12, 2023 Category: How To, Ubuntu

How to compare two directories in Linux recursively and compare files in two directories. This tutorial explains how to compare two directories for missing files and differences in Linux.

Compare two directories for missing files in Linux

The ‘comm’ command is used to compare two sorted files line by line. The ‘comm’ writes to standard output lines that are common, and lines that are unique, to two input files; a file name of ‘-’ means standard input.

Note that when no options are provided, the ‘comm’ produces three-column output. Where:

  1. Column one contains lines unique to FILE1.
  2. Column two contains lines unique to FILE2.
  3. Column three contains lines common to both files.

The options ‘-1’, ‘-2’, and ‘-3’ can be used to suppress printing of the corresponding columns.

Let us see to use the comm command. The syntax of the comm command is: comm <(ls dir1) <(ls dir2)

Note that with no options, ‘comm’ produces three-column output. Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files. These three columns are separated by a single “tab” character.

To show and print file unique in Dir1, use the following command:

comm -23 <(ls dir1) <(ls dir2)

To show and print file unique in Dir2, use the following command:

comm -13 <(ls dir1) <(ls dir2)

To print file common in both directory, you should use the following command:

comm -12 <(ls dir1) <(ls dir2)

You can also use the diff command to compare directories in Linux. The diff command has a simple syntax: diff -qr Directory-1 Directory-2

Compare files in two directories in Linux

Note that if you want to compare files in two directories in Linux, use the command option -r with command. It is so because by default, the diff command won’t look for the files inside the subdirectory.

Primary Sidebar

Latest Posts

Ubuntu 25.04 ‘Plucky Puffin’ Is Available To Download

How to Login as Root User in Linux Terminal

Install Firefox In Ubuntu Terminal Command Line

How To Check Kernel Installed Date In Linux Ubuntu

How To List All Kernel Modules That Are Loaded In Ubuntu

Enable Ubuntu Auto Login Without Password

Download Ubuntu 25.04 Official Default Wallpapers

How To Fix Initramfs Error In Ubuntu Command Line

How To Check All Available Kernel Version In Linux Ubuntu

3 Best Artificial Intelligence Domain Name Generators

© 2025 Source Digit • Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • About
  • Privacy Policy
  • Terms & Conditions
  • Contact Us
  • Sitemap