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.


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.

Universal configuration monitoring and system of record for IT.
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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

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
10
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 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

how about:

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

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

Comment by braino 376 weeks and 4 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 376 weeks and 4 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 376 weeks and 4 days ago
(echo ${SSH_CLIENT%% *} | awk -F: '{print$NF}')
Comment by catawampus 376 weeks and 1 day 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 375 weeks and 4 days ago

thanks for the tip. All fixed.

Comment by braino 375 weeks and 4 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 360 weeks and 4 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 360 weeks and 4 days ago

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

Comment by Dachaz 236 weeks ago

Your point of view

You must be signed in to comment.