Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Copy a folder tree through ssh using compression (no temporary files)

Terminal - Copy a folder tree through ssh using compression (no temporary files)
ssh <host> 'tar -cz /<folder>/<subfolder>' | tar -xvz
2009-11-10 20:06:47
User: polaco
Functions: ssh tar
9
Copy a folder tree through ssh using compression (no temporary files)

This command will copy a folder tree (keeping the parent folders) through ssh. It will:

- compress the data

- stream the compressed data through ssh

- decompress the data on the local folder

This command will take no additional space on the host machine (no need to create compressed tar files, transfer it and then delete it on the host).

There is some situations (like mirroring a remote machine) where you simply cant wait for a huge time taking scp command or cant compress the data to a tarball on the host because of file system space limitation, so this command can do the job quite well.

This command performs very well mainly when a lot of data is involved in the process. If you copying a low amount of data, use scp instead (easier to type)

Alternatives

There is 1 alternative - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

What others think

In case you want to use fewer CPU cycles, you could just drop the gzip compression of tar (which is sometimes the bottleneck depending on the data), or use a different cipher in ssh:

ssh <host> -C blowfish-cbc 'tar -cz /<folder>/<subfolder>' | tar -xvz

to profile the different ssh ciphers on your machine, run this command:

openssl speed aes rc4 blowfish

At least on debian/ubuntu, the openssl command comes with the 'openssl' package, which is probably available by default on most systems.

Comment by bwoodacre 230 weeks and 6 days ago

Nice comment, thx for the additions

Comment by polaco 230 weeks and 5 days ago

You can let ssh do the compression/decompression:

ssh -C HOST 'tar -c PATH' | tar -xv

The advantage is that you can control the compression level, like:

ssh -C -o CompressionLevel=9 HOST 'tar -c PATH' | tar -xv
Comment by rbossy 230 weeks and 4 days ago

Did some testes with the 3 versions of the commands (copying large log files)

time scp hula2:/export/logs/account-collector/server.log.2009-11-* .

server.log.2009-11-01 100% 43MB 8.5MB/s 00:05

server.log.2009-11-02 100% 44MB 10.9MB/s 00:04

server.log.2009-11-03 100% 21MB 10.5MB/s 00:02

server.log.2009-11-04 100% 2302KB 2.3MB/s 00:00

server.log.2009-11-05 100% 785MB 9.7MB/s 01:21

server.log.2009-11-06 100% 50MB 8.3MB/s 00:06

server.log.2009-11-07 100% 21MB 10.4MB/s 00:02

server.log.2009-11-08 100% 20MB 10.2MB/s 00:02

server.log.2009-11-09 100% 5171KB 5.1MB/s 00:01

server.log.2009-11-10 100% 343MB 8.8MB/s 00:39

server.log.2009-11-11 100% 109MB 9.1MB/s 00:12

server.log.2009-11-12 100% 109MB 8.4MB/s 00:13

real 2m46.731s

user 0m25.078s

sys 0m10.113s

time ssh hula2 'tar -cz /export/logs/account-collector/server.log.2009-11-*' | tar -xvz

tar: Removing leading `/' from member names

export/logs/account-collector/server.log.2009-11-01

export/logs/account-collector/server.log.2009-11-02

export/logs/account-collector/server.log.2009-11-03

export/logs/account-collector/server.log.2009-11-04

export/logs/account-collector/server.log.2009-11-05

export/logs/account-collector/server.log.2009-11-06

export/logs/account-collector/server.log.2009-11-07

export/logs/account-collector/server.log.2009-11-08

export/logs/account-collector/server.log.2009-11-09

export/logs/account-collector/server.log.2009-11-10

export/logs/account-collector/server.log.2009-11-11

export/logs/account-collector/server.log.2009-11-12

real 1m8.055s

user 0m7.232s

sys 0m5.428s

time ssh -C hula2 'tar -c /export/logs/account-collector/server.log.2009-11-*' | tar -xv

tar: Removing leading `/' from member names

export/logs/account-collector/server.log.2009-11-01

export/logs/account-collector/server.log.2009-11-02

export/logs/account-collector/server.log.2009-11-03

export/logs/account-collector/server.log.2009-11-04

export/logs/account-collector/server.log.2009-11-05

export/logs/account-collector/server.log.2009-11-06

export/logs/account-collector/server.log.2009-11-07

export/logs/account-collector/server.log.2009-11-08

export/logs/account-collector/server.log.2009-11-09

export/logs/account-collector/server.log.2009-11-10

export/logs/account-collector/server.log.2009-11-11

export/logs/account-collector/server.log.2009-11-12

real 1m28.785s

user 0m13.613s

sys 0m6.332s

The ssh -C option is a good alternative but it probably compresses by packet, achieving a lower compression when compared to compression by file.

Still the -C flag can be very useful.

Thx for the additions guys.

Comment by polaco 230 weeks and 4 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts