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 Zulu from sorted by
Terminal - Commands by Zulu - 15 results
:r scp://yourhost//your/file
2013-09-16 08:09:53
User: Zulu
Tags: vim scp
1

Like vim scp://yourhost//your/file but in vim cmds.

dpkg --list | grep '^rc\b' | awk '{ print $2 }' | xargs sudo dpkg -P
dtruss [ -p <pid> | -n <pname> ]
. (in NORMAL MODE)
2013-01-08 18:32:57
User: Zulu
Tags: vim
-3

Paste what you previously wrote in INSERT MODE, for example:

1. Write 'foo' in INSERT MODE

2. Return to NORMAL MODE

3. Press "." and it will paste 'foo'

CTRL + A ( in normal mode )
d + %
2012-07-12 01:04:40
User: Zulu
Tags: vim
2

We have for example :

func () {

echo FOO

echo BAR

}

Place the cursor under a bracket and press d + %.

It will cut everything inside and the brackets.

It let : func ()

You can copy text with y + %

ls ${PATH//:/ }
2012-04-26 19:45:52
User: Zulu
Functions: ls
9

List all commands present on system by folder.

PATH contains all command folder separated by ':'. With ${PATH//:/ }, we change ':' in space and create a list of folder for ls command.
eval <command> ${INBACK:-&}
2012-04-05 03:50:57
User: Zulu
Functions: eval
Tags: bash eval nohup
-1

If $INBACK is set, command will launch in foreground and inverse.

Very useful in script !

We could apply the inverse comportement like that :

eval command ${INBACK:+&}

while read ; do python <script> ; done
2012-02-23 22:29:09
User: Zulu
Functions: python read
-2

Very useful for test a script. After launch this command, you only have to press ENTER for launch your script again. I work with screen and tape ENTER instead of '!!'+ENTER

If you break your script with CTRL-C, it will wait for press ENTER and will re-launch

You can write like it : while read -p "Press ENTER" ; do python ; done

sed -r 's/(\[|])//g' | awk ' { $1=strftime("%D %T",$1); print }'
2012-02-03 13:07:37
User: Zulu
Functions: awk sed
Tags: sed awk timestamp
0

It remove the square bracket and convert UNIX time to human readable time for all line of a stream (or file).

sed -re '/^#/d ; s/#.*$// ; /^\s*$/d'
2012-02-02 18:12:52
User: Zulu
Functions: sed
Tags: sed
-1

Use it with cat and '|' for know what is used in a conf file.

For example cat /etc/squid/squid.conf | sed -re '/^#/d ; s/#.*$// ; /^\s$/d' :

Show you what you use in your file conf.

It removes all comments and empty lines.

Empty lines are lines with nothing, a tab, or a space.

sed -i <file> -re '<start>,<end>d'
sed -re '/^#/d ; s/#.*$//'
2012-02-01 20:39:23
User: Zulu
Functions: sed
Tags: sed
-1

Delete all comments (#) on text :

It deletes the entire comment line and remove comments form end of others.

while ( nc -l 1025 | bash &> : ) ; do : ; done &
2012-01-08 03:31:58
User: Zulu
Functions: bash
Tags: bash nc dangerous
-8

Allow to launch nc like a daemon, in background until you still stop it.

(like this command: http://www.commandlinefu.com/commands/view/9978 )

For send script or commands from the client to the server, use nc too, like that :

cat script.sh | nc server 1025

echo "service openvpn restart" | nc server 1025

The loop's inside doesn't do anything, but we can add echo -e "\nCommand received\n" .

while ( nc -l 80 < /file.htm > : ) ; do : ; done &
2012-01-02 02:17:25
User: Zulu
Tags: while nc daemon
11

Allow to launch nc like a daemon, in background until you still stop it.

You can stop it with kill %1 (jobs method) or kill PID.

The -k option can force nc to listen another connection, but if you use redirection, it will work only one time.

The loop's inside doesn't do anything, but we can imagine to send a message to screen when a connection is established