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

Commands by SEJeff from sorted by
Terminal - Commands by SEJeff - 10 results
printf -- " -e %s" ${ARRAY[*]}
2014-02-25 03:34:12
User: SEJeff
Functions: printf
1
DOCKER_APP_VARS=(DATABASE_USER=dbuserro, DATABASE_PASSWORD=maipass)

[jeff@omniscience container] (master)$ echo docker run $(printf -- " -e %s" ${DOCKER_APP_VARS[*]}) -name 12factorapp mattdm/fedora-small

docker run -e DATABASE_USER=dbuserro, -e DATABASE_PASSWORD=maipass -name 12factorapp mattdm/fedora-small

Note that the printf method by itsself doesn't include a newline (\n), so you'll need to embed it into an echo statement or something that does.

dmidecode -s system-serial-number
2012-05-25 17:03:37
User: SEJeff
0

This returns the hardware serial number. Dell calls this the "Service Tag" and it can be used to retrieve warranty information or used for RMA / repairs.

awk '{if ($NF ~ "^[a-zA-Z].*[0-9]$" && $NF !~ "c[0-9]+d[0-9]+$" && $NF !~ "^loop.*") print "/dev/"$NF}' /proc/partitions
awk '{if ($NF ~ "^[a-zA-Z].*[a-zA-Z]$" && $NF !~ "name" || $NF ~ "c[0-9]+d[0-9]+$") print "/dev/"$NF}' /proc/partitions
ps aux | awk '{if ($8 ~ "D") print $0}'
2012-05-25 16:53:57
User: SEJeff
Functions: awk ps
0

Lots of fun to run on nfs clients when the server or network connection is having issues

export LESS='-x4FRSXs'
2012-05-25 16:46:15
User: SEJeff
Functions: export
0

# s = combine multiple lines of whitespace into 1

# x4 = set the tabstop to 4 instead of 8

# F = Exit if the output fits on 1 screen. This is similar to git diff

# R = Raw control chars. This allows you to pipe colordiff straight to less. ie: alias sdi="svn diff | colordiff | less"

# S = Chop off long lines

# X = Dont send termcap init and deinit scrings to the terminal

ifconfig eth0 allmulti
2012-05-25 16:43:41
User: SEJeff
Functions: ifconfig
0

Disabling an interface's multicast filter is like disabling IGMP snooping on a switch. It is useful for testing and troubleshooting.

kill -9 -$(ps x -o "%c %r" | awk '/svscan/{print $2}')
2012-05-25 16:39:02
User: SEJeff
Functions: awk kill ps
0

Daemontools[1] won't always properly reap it's children. Sometimes when you need to kill the main svscan process, you want to also clean up all of it's children. The way to do that is to send a signal to the entire process group. It is a bit tricky

[1] http://cr.yp.to/daemontools.html

find /proc/sys/vm -maxdepth 1 -type f | while read i ; do printf "%-35s\t%s\n" "$i" "$(<$i)" ; done | sort -t/ -k4
2012-05-25 16:34:16
User: SEJeff
Functions: find printf read sort
0

Sometimes you want to see all of the systcls for a given $thing. I happened to need to easily look at all of the vm sysctls between two boxes and compare them. This is what I came up with.

lsof +c 15 | awk '{print $1}' | sort | uniq -c | sort -rn | head