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

Easily scp a file back to the host you're connecting from

Terminal - Easily scp a file back to the host you're connecting from
mecp () { scp "$@" ${SSH_CLIENT%% *}:Desktop/; }
2009-06-11 00:43:08
User: braino
Functions: scp
9
Easily scp a file back to the host you're connecting from

Place in .bashrc and invoke like this: "mecp /path/to/file", and it will copy the specified file(s) back to the desktop of the host you're ssh'ing in from. To easily upload a file from the host you're ssh'ing in from use this:

ucp (){ scp ${SSH_CLIENT%% *}:Desktop/upload/* .; }

Alternatives

There are 2 alternatives - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

What others think

how about:

mecp () { scp $@ ${SSH_CLIENT%% *}:Desktop/; }
Comment by rhythmx 267 weeks and 6 days ago

Awesome! Just the improvement I was looking for :) thanks.

Comment by braino 267 weeks and 5 days ago

cygwin produces this error.

cp: cannot create regular file `::ffff:131.204.42.86:Desktop/2.25-win-1.000.pdb': No such file or directory

Comment by thebillywayne 267 weeks and 5 days ago

Looks like cygwin is giving you back an ipv6 address. I think you need to enclose ipv6 addresses in brackets [ ] . Or, if "who" gives you back an ipv4 addresses, you can try replacing this "${SSH_CLIENT%% *}" with the original (ugly hack) code:

`who | grep \`whoami\` | tail -n 1 | awk '{print $5}' | sed 's/\(.*\)./\1/' | sed 's/.\(.*\)/\1/'`

Comment by braino 267 weeks and 5 days ago
(echo ${SSH_CLIENT%% *} | awk -F: '{print$NF}')
Comment by catawampus 267 weeks and 2 days ago

Very useful :) I have both a pull and a push script on half a dozen machines now.

But you need to put the $@ in double quotes or you won't be able to copy files with spaces in their name

scp "$@" ${SSH_CLIENT%% *}:Desktop/

Comment by meph 266 weeks and 5 days ago

thanks for the tip. All fixed.

Comment by braino 266 weeks and 5 days ago

I didn't find this exact syntax to work on my system. Specifically, if I echo $SSH_CLIENT I get three numbers. The first is the IP, the second perhaps the PID, and the third maybe is the port. So I do something like:

SSH_CLIENT_IP="`echo $SSH_CLIENT | awk '{print $1}'`"

mecp () { args=("$@");

scp -P "${args[1]}" "${args[0]}" ${SSH_CLIENT_IP}:downloads/; }

ucp (){ args=("$@");

scp -P "${args[1]}" ${SSH_CLIENT_IP}:downloads/${args[0]} . ; }

Since I also don't default to port 22, then I can say mecp file port, or just hardcode my port of choice.

Comment by daid 251 weeks and 5 days ago

@daid: In order to see the IP you're logged in from, you need:

echo ${SSH_CLIENT%% *}

That uses bash shell expansion pattern matching (%%) to remove the longest matching pattern from the end of what is returned from $SSH_CLIENT. The " *"

will match a space with anything after it.

Comment by braino 251 weeks and 4 days ago

Is it possible to automatically attach the username from the originating host?

Comment by Dachaz 127 weeks and 1 day ago

Your point of view

You must be signed in to comment.

Related sites and podcasts