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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



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!

Top Tags



full memcache client in under 255 chars (uses dd, sed and nc)

Terminal - full memcache client in under 255 chars (uses dd, sed and nc)
mem(){ { case $1 in st*|[vgid]*) printf "%s " "$@";; *) dd if=$3 2>&1|sed '$!d;/^0/d;s/ .*//;s/^/'"$1"' '"$2"' 1 0 /; r '"$3"'' 2>/dev/null;;esac;printf "\r\nquit\r\n";}|nc -n 11211; }
2011-06-17 06:39:07
User: argv
Functions: dd printf sed
full memcache client in under 255 chars (uses dd, sed and nc)

usage: mem memcache-command [arguments]

where memcache-command might be:















exptime argument is set to 0 (no expire)

flags argument is set to 1 (arbitrary)


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

Alas, I don't know much about memcache, but there's a couple of things I can improve.

If you give printf one format specifier, e.g. %s, but several arguments, it will reuse the format:

printf "%s " a b c

displays "a b c"

Next, there's a shell abbreviation, in bash at least, for all the parameters: $@

Quote it to keep any whitespace:

printf "%s " "$@"

Later in the command you use a local variable $a, but you don't alter it, so you may as well use the original $3 (I think).

This shortens your command from 235 to 193 bytes.

mem(){ { case $1 in st*|[gid]*) printf "%s " "$@";; *) dd if=$3 2>&1|sed '$!d;/^0/d;s/ .*//;s/^/'"$1"' '"$2"' 1 0 /; r '"$3"'' 2>/dev/null;;esac;printf "\r\nquit\r\n";}|nc -n 11211; }

Now, if you give us some sample data for the dd/sed part of the command, we'll see if we can simplify that.

Comment by flatcap 318 weeks and 5 days ago

thx flatcap. you're right. i've made your suggested changes, and added another of my own.

when i look at this my mind says the original arg3 should be "reset(lost)" when passing through a pipe. habitually, i use local vars to prevent this as i'm typing one-liners that use a pipe. but you're right, it's not necessary here.

also the last printf isn't necessary if you're using gnu sed.

Comment by argv 318 weeks and 5 days ago

Your point of view

You must be signed in to comment.