Few one-line commands on transferring files from one Linux computer to another

Few one-line commands on transferring files from one Linux computer to another

We are considering tranfering multiple files on the network. Usual actions in this case are:

cd /path/to/folder
tar -zcf archive.tar.gz folder-to-move
scp archive.tar.gz user@remotehost:/path

and eventually unarchiving the file on the remote computer. We'll try to suggest few one-line commands to ease this process.

First let's look at the following line:

(cd /path/to/folder; tar zcvf - folder-to-move) | (ssh user@remotehost 'cd /path; cat > archive.tar.gz')

Advantages here are that no temporary file is created on the source computer which comes handy in case ot little free space. Source mac hine also compresses the file and this reduces traffic between machines, so copying is faster esspecially on slow connections.

However, if network traffic is not an issue (fast speed between machines and cheap traffic) and sending machine is weak and cannot handle well compression then this can be done on the receiver:

(cd /path/to/folder; tar cvf - folder-to-move) | (ssh user@remotehost 'cd /path; cat | gzip > archive.tar.gz')

If we don't care for compression at all we can completely exclude it:

(cd /path/to/folder; tar cvf - folder-to-move) | (ssh user@remotehost 'cd /path; cat > archive.tar')

In case we don't want to archive but just copy the folder we use the following for compressed traffic:

(cd /path/to/folder; tar zcvf - folder-to-move) | (ssh user@remotehost 'cd /path; cat | tar -zxf -')

and for uncompressed:

(cd /path/to/folder; tar cvf - folder-to-move) | (ssh user@remotehost 'cd /path; cat | tar -xf -')

 

No comments yet

Back to articles list

This page was last modified on 2024-04-19 10:09:56