← All commands
Topic hub PowerShell Equivalents
Windows Linux PowerShell Equivalents Text Processing

Windows PowerShell Compare-Object equivalent in Linux

Shows line-by-line differences or compares two already sorted lists.

Windows PowerShell Compare-Object
Linux equivalents
Debian/Ubuntu same command
diff -u old.txt new.txt
Fedora same command
diff -u old.txt new.txt
Arch same command
diff -u old.txt new.txt

Overview

What this command does

Shows line-by-line differences or compares two already sorted lists.

Migration tip: Use diff -u for readable patches. Use comm when both files are sorted and you need unique or shared lines.

Practical tasks

Common use cases

Compare text files

Shows line-by-line differences or compares two already sorted lists.

diff -u old.conf new.conf

Show a unified diff

diff -r folderA folderB

Compare directories recursively

comm -3 <(sort a.txt) <(sort b.txt)

Show lines unique to either list

Ready to run

Copyable Linux commands

Review paths, device names, package names and permissions before running any command.

diff -u old.conf new.conf
diff -r folderA folderB
comm -3 <(sort a.txt) <(sort b.txt)

Walkthrough

Examples with explanations

diff -u old.conf new.conf # compare two text files
diff -r folderA folderB # compare two directories
comm -3 <(sort a.txt) <(sort b.txt) # compare sorted lists

Reference

Common options and variations

Command or optionUse
diff -u old.conf new.confShow a unified diff
diff -r folderA folderBCompare directories recursively
comm -3 <(sort a.txt) <(sort b.txt)Show lines unique to either list

Distro differences

Debian/Ubuntu vs Fedora vs Arch

This command is the same on Debian/Ubuntu, Fedora and Arch Linux when the relevant tool is installed.

DistributionPackage manager / baseEquivalent commandDifference to notice
Debian/Ubuntu same command diff -u old.txt new.txt Same command on this distribution.
Fedora same command diff -u old.txt new.txt Same command on this distribution.
Arch same command diff -u old.txt new.txt Same command on this distribution.

Keep learning

Related PowerShell Equivalents commands