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 rubenmoran from sorted by
Terminal - Commands by rubenmoran - 26 results
dpkg -l |grep i386 | awk '{ print "apt-get -y remove --purge "$2 }' | sh
Limit kernel compilation load
mv file.png $( mktemp -u | cut -d'.' -f2 ).png
tr -dc a-z0-9 </dev/urandom | tr 0-8 \ | tr 9 \\n | sed 's/^[ \t]*//' | fmt -u
find . -type f -printf %s\\n | paste -sd+ | bc
2011-02-10 09:44:36
User: rubenmoran
Functions: find paste
0

Computes total size of files in a directory. This value is different "du -b" because doesn't includes directory sizes.

watch -n1 echo
seq -s^2+ 11 |rev| cut -d'+' -f2- | rev | bc
2011-02-10 08:41:14
User: rubenmoran
Functions: cut rev seq
Tags: seq sum math
-2

I can't put the last ^2 with seq, so I reverse it to delete the last +N. So for doing sum(N^2) you have to do sum((N+1)^2). Must be a better way.

seq -s* 10 |bc
seq 1000 | paste -sd+- | bc
seq 10 | paste -sd* | bc
seq 100000 | paste -sd+ | bc
dpkg -S $( which ls )
sed i"+" file.txt | xargs echo 0 |bc
2011-02-09 10:14:22
User: rubenmoran
Functions: echo sed xargs
Tags: sum
1

In the file data.txt there is a single column of numbers. Sed adds a "+" between lines and xargs prepares the output for bc. The "echo 0" is to avoid to have a "+" at the beginning of the line.

who loves mum
xclip file.txt
2010-06-06 14:28:26
User: rubenmoran
Tags: copy paste
6

Loads file content on clipboard. Very useful when text selection size is higher than console size.

xrandr | grep \* | cut -d' ' -f4
xrandr | grep \*
echo Y29tbWFuZGxpbmUuZnUgcm9ja3MK | base64 -d
touch file-$(date +%Y%m%d)
grep -i "$(date +%b" "%d )13:4[0-5]" syslog
2010-05-23 16:30:46
User: rubenmoran
Functions: grep
Tags: log minutes
6

Returns logs between HH:M[Mx-My], for example, between 13:40 and 13:45.

grep -i "$(date +%b\ %d\ %H)" syslog
2010-05-23 16:18:15
User: rubenmoran
Functions: grep
Tags: log date
6

Uses date to grep de logfile for today and uses it to get the last hour logs. Can be used to get last minute logs or today's logs.

cut -d'/' -f3 file | sort | uniq -c
2010-05-23 16:02:51
User: rubenmoran
Functions: cut file sort uniq
2

count the times a domain appears on a file which lines are URLs in the form http://domain/resource.

sed -n 's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/\nip&\n/gp' ips.txt | grep ip | sed 's/ip//'| sort | uniq
2010-05-23 11:26:32
User: rubenmoran
Functions: grep sed sort
Tags: sed ip address
2

Extracts ip addressess from file using sed. Uses a tag(ip) to grep the IP lines after extracting. Must be a way to just output regex matched on sed.

grep -Eo \([0-9]\{1,3\}[\.]\)\{3\}[0-9] file | sort | uniq
zcat database.sql.gz | mysql -uroot -p'passwd' database
2010-03-23 12:41:57
User: rubenmoran
Functions: zcat
Tags: mysql gzip zcat
5

This way you keep the file compressed saving disk space.

Other way less optimal using named pipes:

mysql -uroot -p'passwd' database <