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 ioggstream from sorted by
Terminal - Commands by ioggstream - 28 results
netstat -town
ip -o -4 a s
2012-09-19 10:59:05
User: ioggstream
4

Short list of all ip.

Shows even the newly supported multiple ip address on the same interface (see eth1).

For ipv6 use -6

ldapsearch -xLLL -b "cn=schema" "(objectclass=*)" \ \* objectclasses attributetypes | perl -p0e 's/\n //g'
2012-04-04 13:31:31
User: ioggstream
Functions: perl
-2

Dump 389ds schema, putting "\n " on one line with perl.

You have to specify the objectclasses, attributetypes operational attributes too, otherwise they won't be dumped!

<ESC> #
2011-09-13 17:01:44
User: ioggstream
6

This should work with different locales. Another post reports

awk '{print $0/60;}' /proc/uptime
2011-08-31 10:41:21
User: ioggstream
Functions: awk
-1

Get info directly from /proc/uptime

list the naming contexts of a directory server (no need to search in config files)
ps -ef | grep c\\ommand
grep -i "$*" /usr/lib/perl5/Unicode/CharName.pm | while read a b; do /usr/bin/printf "\u$a\tU+%s\t%s\n" "$b"; done
2011-01-04 11:30:16
User: ioggstream
Functions: grep read
1

No need for further filedes or substitution for splitting. Simply use read a b

nmap -v -sP 192.168.10.0/24 | grep -c down
wall <<< "Broadcast This"
pgrep -c cat
find -iname \*.[ch] -exec emacs -nw -q {} --eval "(progn (mark-whole-buffer) (indent-region (point-min) (point-max) nil) (save-buffer))" --kill \;
2010-09-10 12:24:58
User: ioggstream
Functions: emacs find
3

use -iname \*[.ch] instead of -iname \*.c -o -iname \*.h

pgrep -cu ioggstream
diff -wubBEr -x .svn dirA dirB
shuf -i 1-49 | head -n6 | sort -n| xargs
2009-10-22 12:54:08
User: ioggstream
Functions: head sort
5

note the xargs at the end

tar dfz horde-webmail-1.2.3.tar.gz
perl -ne 'split /,/ ; $a+= $_[3]; END {print $a."\n";}' -f ./file.csv
ulimit -s 64
2009-08-06 10:40:25
User: ioggstream
Functions: ulimit
Tags: Linux ulimit
1

default stack size is 10M. This makes your multithread app filling rapidly your memory.

on my PC I was able to create only 300thread with default stack size.

Lower the default stack size to the one effectively used by your threads, let you create more.

ex. putting 64k I was able to create more than 10.000threads.

Obviously ...your thread shouldn't need more than 64k ram!!!

ldapmodify -Y "dn:uid=rob,dc=example.com" -g -R -J 2.16.840.1.113730.3.4.16 ...
$ grep -or string path/ | wc -l
export HISTCONTROL=ignoreboth
2009-07-15 16:05:03
User: ioggstream
Functions: export
Tags: history
4

Don't track in history commands starting with whitespace.

Moreover ignore duplicates from history.

To be set in .bashrc

ex.

$ export HISTCONTROL=ignoreboth

$   echo antani

$   history|grep -c antani

export LANG=C; grep string longBigFile.log
2009-07-14 12:48:02
User: ioggstream
Functions: export grep
Tags: grep LANG
0

greps using only ascii, skipping the overhead of matching UTF chars.

Some stats:

$ export LANG=C; time grep -c Quit /var/log/mysqld.log

7432

real 0m0.191s

user 0m0.112s

sys 0m0.079s

$ export LANG=en_US.UTF-8; time grep -c Quit /var/log/mysqld.log

7432

real 0m13.462s

user 0m9.485s

sys 0m3.977s

Try strace-ing grep with and without LANG=C

pkill -9 -f program
2009-07-12 14:46:14
User: ioggstream
Tags: kill pgrep pkill
1

Kills a process matching program. I suggest using

$ pgrep -fl program

to avoid over-killings

Nice the following: kills all bash process owned by guest

$ pkill -9 -f bash -u guest

egrep --color=auto 'usb|' /var/log/messages
2009-07-08 15:20:31
User: ioggstream
Functions: egrep
4

this is useful to highlight only some code without losing other lines (eg. software, logs, scripts)

du -ms * .[^.]*| sort -nk1
2009-07-01 13:38:13
User: ioggstream
Functions: du sort
3

using mb it's still readable;) a symbol variation

$ du -ms {,.[^.]}* | sort -nk1