Windows PowerShell Compare-Object equivalent in Linux
Shows line-by-line differences or compares two already sorted lists.
PowerShell Compare-Object
diff -u old.txt new.txt
diff -u old.txt new.txt
diff -u old.txt new.txt
Overview
What this command does
On Windows, "PowerShell Compare-Object" is used to compare text files. On Linux, the closest practical mapping shown here is "diff -u old.txt new.txt". Shows line-by-line differences or compares two already sorted lists. This reference is grouped under PowerShell Equivalents → Text Processing.
Windows → Linux context
What changes when you use this on Linux?
Equivalent task, different tool
Windows PowerShell Compare-Object maps to diff -u old.txt new.txt for this task. Treat this as a workflow mapping rather than a character-for-character syntax translation.
Portable across the compared distros
The Debian/Ubuntu, Fedora and Arch rows use the same command in this mapping. Package availability or defaults can still vary, so check the installed tool version when an option behaves differently.
For the broader concept behind this mapping, read PowerShell vs Bash.
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 option | Use |
|---|---|
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 |
Distro differences
Debian/Ubuntu vs Fedora vs Arch
Debian/Ubuntu, Fedora and Arch all use "diff -u old.txt new.txt" for this mapping. The command syntax shown here is portable across the three rows, although installed versions and system defaults can still vary.
| Distribution | Package manager / base | Equivalent command | Difference 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