Master `diff` with Process Substitution for Inline Comparisons

Quick Tip

Master `diff` with Process Substitution for Inline Comparisons

Challenge: You need to quickly compare the contents of two files without creating temporary files, or you want to compare the output of two commands directly.

The Solution: Utilize Bash’s process substitution with the `diff` command.

diff <(command1) <(command2)

Why it works: Bash process substitution (`<(…)`) treats the output of a command as if it were a file. This allows `diff` to directly compare the streams of data from two commands without needing to redirect them to temporary files first.

Pro-Tip: You can also use this for comparing two actual files: diff <(cat file1.txt) <(cat file2.txt), which is functionally similar to diff file1.txt file2.txt but demonstrates the process substitution concept.

Linux Tips & Tricks | © ngelinux.com | 4/26/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments