Linux Package Comparison: Find Differences Between 2 Servers

Quick Linux Tip #95:

Question: Two servers behave differently. Which packages differ between them?

Try: diff <(ssh linuxteck@server1 'dpkg -l | awk "/^ii/{print \$2}"' | sort) <(ssh linuxteck@server2 'dpkg -l | awk "/^ii/{print \$2}"' | sort)

Info: dpkg -l lists installed packages, filtered via awk for active (ii) entries. Process substitution pipes remote outputs directly into diff to spot package drift.

Examples:

  • $ diff <(rpm -qa | sort) <(ssh host2 'rpm -qa | sort')  # Compare RHEL/Fedora packages
  • $ diff <(pacman -Q | sort) <(ssh host2 'pacman -Q | sort')  # Compare Arch Linux packages
  • $ comm -23 <(dpkg -l) <(ssh host2 'dpkg -l')  # Show packages unique to server1

Note: SSH public key authentication must be configured for passwordless remote execution. Essential for auditing differences between staging and production environments.




LinuxTeck.com
linuxteck:~$ diff <(ssh linuxteck@server1 'dpkg -l | awk "/^ii/{print \$2}"' | sort) <(ssh linuxteck@server2 'dpkg -l | awk "/^ii/{print \$2}"' | sort)
23a24
> fail2ban
45d45
< postgresql-14
67a68
> redis-server
89d89
< snapd

linuxteck:~$ ssh linuxteck@server1 'dpkg -l | grep -c "^ii"'
1234

linuxteck:~$ ssh linuxteck@server2 'dpkg -l | grep -c "^ii"'
1256

linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #94: Swap File in Linux: Add 4GB Swap Space in 4 Steps NEXT ARTICLE Quick Linux Tip #96: Linux File Access Auditing: Track Who Accessed /etc/shadow
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.