Tar and download in one step over ssh / scp
If you follow your description the command becomes "obvious" (at least, when you see it...). You really weren't far off with your attempt, though:
ssh user@remote tar czf - /my/directory/ > /my/local/destination/archive.tgz
(The "duplicate" link cited by Marco provides a cleaner solution. To create this command here I've simply followed the style of your attempt.)
Related videos on Youtube
phil
Updated on September 18, 2022Comments
-
phil over 1 year
(This seems like an obvious / common question, but I couldn't find it when searching - maybe I wasn't using the correct terminology...)
I want to login over ssh to a remote machine, tar a directory, and download it to my local machine. I don't need to leave a copy on the remote server. Currently I ssh in, create the tar archive, logout, scp the file to my machine, the ssh back in to remove the archive. Not exactly efficient...
I know this doesn't work, but I'm thinking something like:
scp user@remote:"tar czf - /my/directory/" ./my/local/destination/archive.tgz
Or is there a better way?
Thanks.
-
JackDaniels about 9 yearsYour answer was great @roaima
-
arekolek over 7 yearsYou don't need
f -
, standard output is used by default. I like this solution better than the other answer, because this way you can use tab completion. -
roaima over 7 years@arekolek that depends on your
tar
. Some versions default to a tape device.