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
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!
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!
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.
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?