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 cicatriz from sorted by
Terminal - Commands by cicatriz - 18 results
fuser -n tcp -s <port> && echo "+open"
egrep '__NR_' /usr/include/asm/unistd_`getconf -a | awk '$1~/^WORD/{print $2}'`.h | sed -e 's/^#define __NR_//' | column -t
echo -e "Terminal shortcut keys\n" && sed -e 's/\^/Ctrl+/g;s/M-/Shift+/g' <(stty -a 2>&1| sed -e 's/;/\n/g' | grep "\^" | tr -d ' ')
2011-02-10 17:38:05
User: cicatriz
Functions: echo grep sed stty tr
7

This command will give you a list of available keyboard shortcuts according to stty.

supportsWrap(){ ldd `which ${1}` | grep "libwrap" &>/dev/null && return 0 || return 1; }
2010-12-01 15:22:29
User: cicatriz
Functions: grep ldd return
Tags: vim Debian ldd
1

This function returns TRUE if the application supports tcp-wrapping or FALSE if not by reading the shared libraries used by this application.

( apache2ctl -t && service apache2 restart || (l=$(apache2ctl -t 2>&1|head -n1|sed 's/.*line\s\([0-9]*\).*/\1/'); vim +$l $(locate apache2.conf | head -n1)))
2010-11-26 18:12:08
User: cicatriz
Functions: head locate sed vim
3

Checks the apache configuration syntax, if is OK then restart the service otherwise opens the configuration file with VIM on the line where the configuration fails.

i=0;for s in `fuser -l`;do echo $((i++)) $s;done
netstat -lnp6 | grep :8080 | sed 's#^[^\/]*/\([a-z0-9]*\)#\1#'
2010-11-03 14:11:21
User: cicatriz
Functions: grep netstat sed
1

Gets the application's name that's listening from the port 8080 through IPv6

perl -e 'print crypt("PASSWORD",int(rand(128))).$/;'
grep -i "aborted login" /var/log/maillog | awk 'BEGIN{FS="="}{print substr($4,8)}' | cut -d"," -f1
2010-09-29 21:05:31
User: cicatriz
Functions: awk cut grep
0

Prints a list of ip that tried to login on SMTP/IMAP/POP3/etc.

ss -ln | awk '$3~/([0-9]+)/{print $3}' | sed 's/.*\:\([0-9]\+\)$/\1/'
2010-09-21 12:45:52
User: cicatriz
Functions: awk sed
1

ss is a tool that will help you to get all kinds of useful information about the current sockets on a localhost. You can also get the uid of the daemons process using the flag:

ss -le
svn log 2>&1 | egrep '^r[0-9]+' | cut -d "|" -f2 | sort | uniq -c
ps ax --format=pid,eip,esp,user,command
2010-09-02 12:40:41
User: cicatriz
Functions: ps
3

'ps' let you specify the format that you want to see on the output.

setserial -g /dev/ttyS[0-9]* | grep -v "unknown"
ldd /bin/bash | awk 'BEGIN{ORS=","}$1~/^\//{print $1}$3~/^\//{print $3}' | sed 's/,$/\n/'
2010-08-06 12:18:56
User: cicatriz
Functions: awk ldd sed
2

For example, you need to make a copy of all the libraries that a certain application uses, with this command you can list and copy them.

ls -la | grep $(date +%Y-%m-%d) | egrep -v -e '\.{1,2}' | sed "s/.*\:[0-9]\{2\} \(.\+\)$/\\1/g"
netstat -l -p --tcp | egrep -e 'www.*[0-9]{3,4}\/(apache2|httpd)' | awk '{print$7}'
egrep '(\[error\])+.*(PHP)+' /var/log/apache2/error.log
awk '$1~/^DocumentRoot/{print $2}' /etc/apache2/sites-available/default