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

All commands from sorted by
Terminal - All commands - 11,951 results
echo lowercaseword | tr '[a-z]' '[A-Z]'
rename s/ .php/ .html/ *.html
hashalot -s salt -x sha256 <<<"test"
2010-11-30 19:32:29
User: vayn
Tags: hash
-1

It's inspired by Generate MD5 hash for a string() [ http://goo.gl/ObCrl ], you need to install hashalot(very small) first. Salt is not necessary.

There is an optional command:

sha256 -s salt -x <<<"test"
mtr google.com
2012-02-19 22:27:48
User: d_voge
-1

You need to have mtr installed on your host.

alias mplayer='mplayer -stop-xscreensaver'
host google.com|awk '{print $NF}'
ggdG
cat /dev/sda | pv -r > /dev/null
2011-01-23 22:58:56
User: kerim
Functions: cat
-1

Change your drive letter as you wish.

Using pv command for speed detect.First of all you must install pv command for usage.

http://www.bayner.com/

kerim@bayner.com

find . -type f -iname '*.java.orig' -delete
find . -printf "%T@ %p\n" | sed -e 1d | while read ts fn; do ts=${ts%.*}; if [ $ts -ge ${gts:-0} ]; then gts=$ts; echo `date -d @$gts` $fn; fi; done
:%s/^V^M//g
2009-08-19 11:59:22
User: slim
-1

Whereas ^V is CTRL-V.

converts a dos file to unix by removing 0x13 characters

ifconfig eth0 | perl -ne 'print $1 if m/addr:((?:\d+\.){3}\d+)/'
makepasswd --char=32
2010-09-29 06:01:32
User: zed
-1

A more robust password creation utility

# Create passwords in batch

makepasswd --char=32 --count=10

# To learn more about the options you can use

man makepasswd
for I in `find . -name "*.php"`; do sed -i "s/old name/new name/g" $I; done
2009-02-16 17:09:09
User: ruedu
Functions: sed
-1

So you have a web site and you've plastered your significant other's name all over it. But you broke up with them and have some new love in your life. How do you find all those instances of their name and replace them?

cat /proc/acpi/battery/BAT1/info
2009-03-21 06:09:37
User: Vlad003
Functions: cat
Tags: bash battery
-1

Displays all information about your battery. for just capacity, try replacing cat with

grep -F capacity:

Battery number might be BAT0 instead of BAT1. Just run

cd /proc/acpi/battery; ls

and find out what folder is in that directory and replace that name with BAT1

rhost() { if [[ $1 =~ ^[0-9]+$ ]]; then sed -i "$1"d ${HOME}/.ssh/known_hosts; else echo "rhost [n]"; fi }
2013-08-01 21:10:34
User: lowjax
Functions: echo sed
-1

Quickly remove the conflicting line (key) from current users known_hosts file when there is an SSH host conflict. Very nice when you get tired of writing out full commands. Ideally you would place this into your .bash_profile

Usage: rhost [n]

Example: rhost 33 (removes line 33 from ~/.ssh/known_hosts)

Function assumes the $HOME exists, you could alternatively use "~/.ssh/known_hosts"

Mac OSX likes a space for sed -i "$1" d

curl -s http://www.last.fm/user/$LASTFMUSER | grep -A 1 subjectCell | sed -e 's#<[^>]*>##g' | head -n2 | tail -n1 | sed 's/^[[:space:]]*//g'
git branch -a | grep "remotes/origin" | grep -v master | awk -F / '{print $3}' | xargs -I % git clone -b % git://github.com/jamesotron/DevWorld-2010-Cocoa-Workshop %
TIME=$( { time redis-cli PING; } 2>&1 ) ; echo $TIME | awk '{print $3}' | sed 's/0m//; s/\.//; s/s//; s/^0.[^[1-9]*//g;'
2011-08-11 19:09:49
User: allrightname
Functions: awk echo sed time
-1

Outputs the real time it takes a Redis ping to run in thousands of a second without any proceeding 0's. Useful for logging or scripted action.

((x++))
watch 'dmesg | tail -15'
2009-12-20 02:00:05
User: Heoa
Functions: tail watch
-1

Useful with new unknown devices or just monitoring, probably useful for the sysadmin. Updates every 2 seconds. More here: http://linuxclisecurity.blogspot.com/2009/12/monitor-kernel-ring-buffer.html.

df /media/mountpoint |egrep -o '^[/a-z0-9]*'
2011-01-24 21:14:55
User: DaveQB
Functions: df egrep
Tags: grep,df
-1

Shorter way to find the device for a given mountpoint

while true; do sleep $(($RANDOM/1000)) && beep -f 2000 -l $(($RANDOM/100)) ; done
lynx "futz.me/xxx hey this is a test"
2009-09-24 19:23:41
-1

Allows you to send yourself notes from the commandline and receive them via email or text message. Also lets you send pics from the web, pics from your computer, and tweets directly to twitter. All without having to log in Ever.