Quickly pipe a directory over ssh
Sometimes I find it useful to quickly pipe directory contents over ssh.
Since scp
only allows to copy single files, a good solution is to simply tar a directory up, and pipe the resulting archive to ssh.
$ tar zcf - some_dir | ssh user@host 'tar zxf -'
To extract to somewhere else than ~
you can specify the path with -C
:
$ tar zcf - some_dir | ssh user@host 'tar zxf - -C /tmp/'
Note, that the directory you are trying to extract to must exist on the server.
To copy from remote to local, simply do the inverse:
$ ssh user@host 'tar zcf - some_dir' | tar zxf -
or with -C
$ ssh user@host 'tar zcf - some_dir' | tar zxf - -C /tmp/
Written by jottr
Related protips
2 Responses
You say "scp only allows single files".. I regularly use wildcards & -r (recursive) with scp, without issue.
over 1 year ago
·
Why not use rsync?
rsync -az --progress /local/dir user@host:/target/path
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#