How can I quickly compare config files with their old versions using a one-liner?

0
0
Asked By TechyTurtle42 On

I'm trying to find a compact way to diff or compare updated config files against their older versions on Debian and Arch. For Debian, I can locate the relevant files using `sudo find /etc/ ( -name '*.dpkg-*' -o -name '*.ucf-*' )`, which works great. For Arch, the process is similar with pacnew files. I want to use `diff -uN` to compare the files, but I'm having trouble condensing this into a single command without writing out a whole script. Can someone provide a quick one-liner for this?

2 Answers

Answered By CodeNinja88 On

You can use this command to achieve what you need: `sudo find /etc -type f ( -name "*.dpkg-*" -o -name "*.ucf-*" ) -exec sh -c 'for f; do diff -Nu "$f" "${f%.*}"; done' _ {} +` This will run `diff` for each found file, comparing it to the corresponding older version by removing the extension. It’s pretty neat!

ScripterSam -

That’s the solution I was stuck on! Can you explain what `_ {}` does in the command? I know `_` is positional, but how does it work here?

Answered By CuriousCoder On

Have you tried something like `diff <(cat file1) <(cat file2)`? I'm not sure if you're mainly looking to compare content or just check for existence, but that could be an option. Let me know how it goes!

FileFinder99 -

I think I need to generate file names from a find operation since the second file should be based on the first one; just `diff file1 file2` won't work in this case.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.