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/
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.
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
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:
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/* .; }
There is 1 alternative - vote for the best!
If you can do better, submit your command here.
You must be signed in to comment.
how about:
mecp () { scp $@ ${SSH_CLIENT%% *}:Desktop/; }Awesome! Just the improvement I was looking for :) thanks.
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
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/'`
(echo ${SSH_CLIENT%% *} | awk -F: '{print$NF}')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/
thanks for the tip. All fixed.
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.
@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.
Is it possible to automatically attach the username from the originating host?