4 ms·
I think diff & patch already serve us well for a few decades.
by imhoguy 6y ago
I think diff & patch already serve us well for a few decades.
- johntash 6y agoI never thought about using diff+patch as an alternative to tar, but I just tried this and it does work as expected: mkdir dir1 dir2 dir3 for x in {1..99};do echo $x > dir1/$x.txt;date >> dir1/$x.txt;done diff -urN dir2 dir1 > dirs.diff cd dir3 patch -i ../dirs.diff -p1 After that, dir3 has the same contents as dir1 had. I couldn't figure out how to make diff consider all files in a directory as new though, without having an empty directory to compare it to.
- imhoguy 6y agoAs you already use GNU diff's `-N` then you can pass any non existing as the first directory: diff -urN /dev/null-non-existing-dir dir1 > x.diff Or use `mktemp -d`. It is still cheaper than investing into some niche tooling without groundbreaking capabilities.
- johntash 6y agoThanks! I didn't realize you could pass in a non-existent directory, that makes it an easier trick.
- breck 6y agoI would be open to a PR adding a link to a good diff/patch way of doing this.