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

move a lot of files over ssh

Terminal - move a lot of files over ssh
tar -cf - /home/user/test | gzip -c | ssh user@sshServer 'cd /tmp; tar xfz -'
2009-08-24 18:35:38
User: esplinter
Functions: gzip ssh tar
11
move a lot of files over ssh

Useful to move many files (thousands or millions files) over ssh. Faster than scp because this way you save a lot of tcp connection establishments (syn/ack packets).

If using a fast lan (I have just tested gigabyte ethernet) it is faster to not compress the data so the command would be:

tar -cf - /home/user/test | ssh user@sshServer 'cd /tmp; tar xf -'

Alternatives

There are 4 alternatives - vote for the best!

Terminal - Alternatives
rsync -az /home/user/test user@sshServer:/tmp/
2009-08-25 10:45:15
User: peshay
Functions: rsync
Tags: ssh file move
14

copy files to a ssh server with gzip compression

tar cfX - exclude_opt_weblogic . | ssh tmp-esxsb044 "cd /opt/weblogic ; tar xf -"

Know a better way?

If you can do better, submit your command here.

What others think

tar -czf and you spare that gzip pipe

Comment by lv4tech 270 weeks and 4 days ago

why not try a nc? Here, I am assuming that you have shells open in both the systems. The netcat manual has an example which does just that.

@lv4tech : i believe that tar internally does the same, pipes it to gzip if its -z, and bzip2 if its -j.

Comment by ninadsp 270 weeks and 4 days ago

You could also have ssh use a different (maybe less "secure") cipher like Blowfish or RC4:

tar -zcf - dirname | ssh -C blowfish-cbc user@host "cd /tmp; tar xfz -"

see the different speeds yourself:

openssl speed aes rc4 blowfish

It'd be interesting to see how nc does versus ssh -C with blowfish or rc4/arcfour.

Comment by bwoodacre 270 weeks and 3 days ago

Is this really saving tcp connection establishment? I tried this with many mp3 files and what I observed was, as soon as I start running it, I start seeing mp3 files in destination. So, it looks like, as if, tar is archiving/compressing single mp3, sending it through ssh and then single archive file is uncompressed at destination. So, my question is, in this case, does tar archive files one by one or compress them into single archive?

Comment by alperyilmaz 235 weeks ago

the tar xfz on the ssh side should be zxf

Comment by elilindner 71 weeks and 2 days ago

@alperyilmaz: Yes, tar creates a stream of files. Think if it as a multi-file cat command. As the stream is sent over the wire it is one TCP connection, The tar command would then write those files as the stream comes across there by looking like it is file by file.

Comment by Sukima 11 weeks and 4 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts