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 lingo from sorted by
Terminal - Commands by lingo - 11 results
cat input.txt | sed 's/\\\033[^a-zA-Z]*.//g'
gpg --list-sigs | sed -rn '/User ID not found/s/^sig.+([a-FA-F0-9]{8}).*/\1/p' | xargs -i_ gpg --keyserver-options no-auto-key-retrieve --recv-keys _
2011-07-22 16:31:25
User: lingo
Functions: gpg sed xargs
Tags: GPG sed fetch
0

For instance, if people have signed your key, this will fetch the signers' keys.

git diff --numstat | awk '{if ($1 == "0" && $2 == "0") print $3}' | xargs git checkout HEAD
2009-09-17 22:12:50
User: lingo
Functions: awk diff xargs
4

I sometimes (due to mismanagement!) end up with files in a git repo which have had their modes changed, but not their content. This one-liner lets me revert the mode changes, while leaving changed-content files be, so I can commit just the actual changes made.

git diff --numstat -w --no-abbrev | perl -a -ne '$F[0] != 0 && $F[1] !=0 && print $F[2] . "\n";'
2009-08-19 05:07:58
User: lingo
Functions: diff perl
1

Only shows files with actual changes to text (excluding whitespace). Useful if you've messed up permissions or transferred in files from windows or something like that, so that you can get a list of changed files, and clean up the rest.

git show --relative --pretty=format:'' --name-only HASH
2009-08-14 03:36:03
User: lingo
Tags: git files list
2

Lists ONLY the files changed by the given HASH/HEAD/list of hashes, etc. The message, commit ID, author, etc. is not included

rename 's/^/prefix/' *
2009-08-14 03:26:45
User: lingo
Functions: rename
12

Best to try first with -n flag, to preview

cd !$:h
2009-08-07 00:37:08
User: lingo
Functions: cd
25

Uses the last argument of the last executed command, and gets the directory name from it.

Use $!:t for the filename alone, without the dirname.

for I in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $I | gzip > "$I.sql.gz"; done
cat files.txt | xargs tar -cv | tar -x -c $DIR/
2009-08-06 22:55:21
User: lingo
Functions: cat tar xargs
0

If you want certain files out of a directory hierarchy, this will copy just the listed files, but will create the directory hierarchy in the new location ($DIR/)

/usr/sbin/apache2ctl -S
2009-07-21 10:52:49
User: lingo
0

Simply shows virtualhosts enabled, root access not needed (assuming apache2ctl is non-root executable).

/usr/sbin/apache2ctl -S 2>&1 | perl -ne 'm@.*port\s+([0-9]+)\s+\w+\s+(\S+)\s+\((.+):.*@ && do { print "$2:$1\n\t$3\n"; $root = qx{grep DocumentRoot $3}; $root =~ s/^\s+//; print "\t$root\n" };'
2009-07-21 10:51:30
User: lingo
Functions: perl
4

Lists virtualhosts currently enabled for apache2, showing the ServerName:port, conf file and DocumentRoot