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 P17 from sorted by
Terminal - Commands by P17 - 19 results
for a in *; do mv $a prefix${a}; done
egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' file.txt
kill_daemon() { echo "Daemon?"; read dm; kill -15 $(netstat -atulpe | grep $dm | cut -d '/' -f1 | awk '{print $9}') }; alias kd='kill_daemon
2009-05-26 20:39:56
User: P17
-5

Just find out the daemon with $ netstat -atulpe. Then type in his name and he gets the SIGTERM.

ip route show dev eth0 | awk '{print $7}'
2009-05-26 20:29:54
User: P17
Functions: awk route
Tags: IP
2
ip address show | grep eth0 | sed '1d' | awk '{print $2}'

does the same, but shows network-prefix.

aptitude remove $(deborphan)
for a in path/* ; do ccenrypt -K <password> $a; done
2009-05-08 18:33:23
User: P17
Tags: Encryption
4

To decrypt the files replace "ccenrypt" with "ccdecrypt.

ccrypt(1) must be installed. It uses the AES (Rijndael) block cipher.

To make it handier create an alias.

rm_cache() { rm -f $HOME/.mozilla/firefox/<profile>/Cache/* }; alias rmcache='rm_cache'
lsof -i | grep -i estab
PS1="$BLUE[$CYAN\u$BLUE@$CYAN\h$WHITE-bash \v:$GREEN\w$BLUE]$WHITE \$ "
2009-05-06 08:01:06
User: P17
Tags: bash
-3

The colors are defined as variables.

e.g.

RED="\[\033[01;31m\]"

BLUE="\[\033[01;34m\]"

alias xdef_load='xrdb -merge ~/.Xdefaults'
2009-05-05 16:34:06
User: P17
Functions: alias
0

Reads in the ~/.Xdefaults lexicographically sorted with, instead of replacing, the current contents of the specified properties.

alias b='cd -'
grep -i --color=auto
2009-04-27 15:03:28
User: P17
Functions: grep
12

Highlights the search pattern in red.

echo "Hello world" | base64
2009-04-27 15:00:08
User: P17
Functions: echo
Tags: encoding
-3

Also works with files:

cat file

Hello world

base64 file

SGVsbG8gd29ybGQK

To decrypt use the -d option:

echo SGVsbG8gd29ybGQK | base64 -d

Hello world

find . -maxdepth 1 -type f -name '*.sh' -o -name '*.txt'
echo "string" | sed -e 's/.*match1//' -e 's/match2.*$//'
2009-04-01 15:01:27
User: P17
Functions: echo sed
-3

But who knows to delete the rest of the lines?

I want only "string".

perl -ne 'while (/([0-9]+\.){3}[0-9]+/g) {print "$&\n"};' file.txt
alias tproxy='ssh -ND 8118 user@server&; export LD_PRELOAD="/usr/lib/libtsocks.so"'
alias myip='curl -s www.wieistmeineip.de | egrep -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"'
head -c $((<pw-lenght>-2)) /dev/urandom | uuencode -m - | sed -e '1d' -e '3d' | sed -e 's/=.*$//g'
2009-03-24 20:05:16
User: P17
Functions: head sed uuencode
-2

Replace < pw-length > with the desired password-length.

The password-length is not always correct, but wayne...