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 tagged edit from sorted by
Terminal - Commands tagged edit - 11 results
sed -e "s/^127.0.1.1 $(hostname).novalocal/127.0.1.1/g" /etc/hosts
2014-09-25 15:38:43
User: renoirb
Functions: sed
0

When booting a VM through OpenStack and managed through cloudinit, the hosts file gets to write a line simiar to

127.0.1.1 ns0.novalocal ns0

This command proven useful while installing a configuration manager such as Salt Stack (or Puppet, or Ansible) and getting node name

vim some-archive.tar.gz
2012-04-20 02:37:28
User: ktonga
Functions: vim
5

If you vim a compressed file it will list all archive content, then you can pickup any of them for editing and saving. There you have the modified archive without any extra step. It supports many file types such as tar.gz, tgz, zip, etc.

vi +4 /etc/mtab
2011-09-15 19:18:00
User: totti
Functions: vi
Tags: edit text line goto
1

This is not printing, real editing using the text editor.

vim `find . -iname '*.php'`
2011-05-11 01:19:28
User: wsams
Functions: vim
0

In this case, we'll be editing every PHP file from the current location down the tree.

You can show all the files in the vim buffer with :buffers which outputs something like,

:buffers

1 %a "./config/config.php" line 1

2 "./lib/ws-php-library.php" line 0

3 "./lib/css.php" line 0

4 "./lib/mysqldb.class.php" line 0

5 "./lib/config.class.php" line 0

6 "./lib/actions.php" line 0

Press ENTER or type command to continue

If you'd like to edit ./lib/mysqldb.class.php for example, enter :b4 anytime you're editing a file. You can switch back and forth.

bsro3 () { P=`pwd`; S=$1; R=$2; ls *.odt > /dev/null 2>&1; if [[ $? -ne 0 ]]; then exit 1; fi; for i in *.odt; do mkdir ${P}/T; cd ${P}/T; unzip -qq "$P"/"$i"; sed -i "s/$S/$R/" ${P}/T/content.xml; zip -qq -r "$P"/"$i" *; cd ${P}; rm -rf ${P}/T; done; }
2010-06-30 04:43:54
User: danpos
Functions: cd exit ls mkdir rm sed
2

This function does a batch edition of all OOO3 Writer files in current directory. It uses sed to search a FOO pattern into body text of each file, then replace it to foo pattern (only the first match) . I did it because I've some hundreds of OOO3 Writer files where I did need to edit one word in each ones and open up each file in OOO3 gui wasn't an option. Usage: bsro3 FOO foo

!:-
2010-05-15 15:12:47
User: new_user
Tags: bash edit
61
/usr/sbin/ab2 -f TLS1 -S -n 1000 -c 100 -t 2 http://www.google.com/

then

!:- http://www.commandlinefu.com/

is the same as

/usr/sbin/ab2 -f TLS1 -S -n 1000 -c 100 -t 2 http://www.commandlinefu.com/
vi +/pattern [file]
2010-04-24 22:15:12
User: punkwalrus
Functions: vi
Tags: vim edit vi
25

Open up vi or vim at the first instance of a pattern in [file]. Useful if you know where you want to be, like "PermitRootLogin" in sshd_config. Also, vi +10 [file] will open up a file at line 10. VERY useful when you get "error at line 10" type of output.

<alt+q>
2009-10-29 14:55:12
User: luther
Tags: edit zsh
5

When writing on the command line of zsh, by pressing Alt+q the command will be cleaned, and you can insert another one. The command you were writing will be recorder, and pasted on the prompt immediately after the "interrupting" command is inserted.

vim -x <FILENAME>
2009-05-05 23:24:17
User: denzuko
Functions: vim
64

While I love gpg and truecrypt there's some times when you just want to edit a file and not worry about keys or having to deal needing extra software on hand. Thus, you can use vim's encrypted file format.

For more info on vim's encrypted files visit: http://www.vim.org/htmldoc/editing.html#encryption

bvi [binary-file]
2009-03-24 15:30:50
User: haivu
Tags: edit
-3

bvi is your vi for binary editing. If your system does not have it, you can get it from

http://bvi.sourceforge.net/

echo -n $HEXBYTES | xxd -r -p | dd of=$FILE seek=$((0x$OFFSET)) bs=1 conv=notrunc
2009-03-11 17:02:24
User: zombiedeity
Functions: dd echo
2

Replace (as opposed to insert) hex opcodes, data, breakpoints, etc. without opening a hex editor.

HEXBYTES contains the hex you want to inject in ascii form (e.g. 31c0)

OFFSET is the hex offset (e.g. 49cf) into the binary FILE