What is the idiomatic way to do the following
- tar to stdout
- read this tar output from stdout and extract to some other folder.
My solution is
tar --to-stdout .. | tar -C somefolder -xvf -
But may be there is more idiomatic way to do it.
What is the idiomatic way to do the following
My solution is
tar --to-stdout .. | tar -C somefolder -xvf -
But may be there is more idiomatic way to do it.
The same -f - option works for tarring as well.
tar -cf - something | tar -C somefolder -xvf -
GNU tar uses stdio by default:
tar -c something | tar -C somefolder -xv
rsync is also popular.
rsync -av something/ somefolder/
Just adding another use-case here. I had a large directory structure on a system nearly out of disk space and wanted to end up with a tar.gz file of the directory structure on another machine with lots of space.
tar -czf - big-dir | ssh user@host 'cat > /path/to/big-dir.tar.gz'
This saves on network overhead and means you don't have to tar on the other side in case you'd wanted to use rsync for the transfer instead.
I don't have enough reputation to post a comment about using netcat.
On the receiving end run:
netcat -l 5555 > /path/to/dest.tar.gz or netcat -l 5555 | tar -C /path/to/expanded/tar -xz
On the sending side run:
tar -C /path/to/source -cz files | netcat <target IP/hostname> 5555
If you are on a fast network, don't bother compressing and decompressing the tar. Used some variant of this over the years for all kinds of recovery.
man tarand search for "remote" there are no matches. Personally I didn't know tar had remote capabilities. – quickshiftin Sep 06 '22 at 14:49tar --zstd -cf 192.168.1.2:/home/user/backup.tar.zstd --rsh-command=/usr/bin/ssh ./see this man page. – ReeseWang Sep 07 '22 at 16:26