3 ms·
I 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..
by johntash 6y ago
I 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.