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.

Universal configuration monitoring and system of record for IT.
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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Hide

Credits

All commands from sorted by
Terminal - All commands - 12,182 results
/sbin/ifconfig | grep inet | cut -f 2 -d ":" | cut -f 1 -d " "
2009-07-21 21:42:04
User: random_bob
Functions: cut grep
-1

another way to output the IP address' of the system

sensible-browser http://www.pythonchallenge.com/pc/def/$(bc <<< 2^38).html
2010-02-02 00:53:18
User: kzh
Functions: bc
-1

This is the answer to the 0th problem from the python challenge < http://www.pythonchallenge.com/ >. Replace sensible-browser with firefox, w3m or whatever.

watch -n1 echo
montage input.jpg -auto-orient -duplicate 7 -geometry 500 -frame 5 output.jpg
2011-06-09 14:03:01
User: anthony
-1

Yes, You could do it in the GIMP or even use Inkscape, but the command line is so much easier.

This is a new version of a previous command fixing some things complained about.

help shopt
kill -9 $(pidof *program*)
crontab -l | sed -e '$G;$s-$-'"$CRON_MINS $CRON_HOUR"' * * * /usr/bin/command >/dev/null 2>&1-' | crontab -
2010-01-07 11:00:05
User: JohnGH
Functions: crontab sed
-1

I needed to add a line to my crontab from within a script and didn't want to have to write my own temporary file.

You may find you need to reload the crond after this to make the change take effect.

e.g.:

if [ -x /sbin/service ]

then

/sbin/service crond reload

else

CRON_PID=`ps -furoot | awk '/[^a-z]cron(d)?$/{print $2}'`

if [ -n "$CRON_PID" ]

then

kill -HUP $CRON_PID

fi

fi

The reason I had CRON_HOUR and CRON_MINS instead of numbers is that I wanted to generate a random time between midnight & 6AM to run the job, which I did with:

CRON_HOUR=`/usr/bin/perl -e 'printf "%02d\n", int(rand(6))'` CRON_MINS=`/usr/bin/perl -e 'printf "%02d\n", int(rand(60));'`
convert input.png -pointsize 32 -gravity center -annotate 45 "hello, world" output.png
find $(locate hello) -type f -executable -print|grep -E "hello\$"
2012-08-18 07:51:53
Functions: find grep locate
-1

This command allow you quick find any executable by keyword(s) in your system.

NOTE: Sometime this command will output like this:

`hello.py.launch': No such file or directory

this is normal behaviour

find -type f -printf '%P\000' | egrep -iz '\.(avi|mpg|mov|flv|wmv|asf|mpeg|m4v|divx|mp4|mkv)$' | sort -z | xargs -0 ls -1
/sbin/ifconfig | grep inet | cut -f 2 -d ":" | cut -f 1 -d " " |egrep -v "^$"
for i in `seq 254`;do ping -c 1 192.168.10.$i > /dev/null && echo "$i is up"||echo "$i is down";done
cls && ipconfig | findstr -R "[ IPv4 | adapter ]"
mdfind "tag:data" > /tmp/data.txt ; zip -r9@ ~/Desktop/data.zip < /tmp/data.txt
2009-02-24 14:49:50
User: vranx
Tags: Os X
-1

finding all files with the metadata tag "data" using the metadata find command mdfind , writing the list to a temporary file, reading the input for the .zip file from this temporary file.

echo $X | egrep "^[0-9]+$"
find . -iname \*.[ch] -exec indent "{}" \;
2010-09-10 13:25:10
User: putnamhill
Functions: find
-1

This version uses the indent C formatting utility. Doesn't appear to be included with ubuntu. But CentOS and MacOS have it.

flipf(){ if [ -f "$1" -a -f "$2" ]; then mv "$1" "$1.$$" && mv "$2" "$1" && mv "$1.$$" "$2" || echo "$!"; else echo "Missing a file: $!"; fi; }
for file in "* *"; do mv "${file}" "${file// /_}"; done
ls /var/log/sa/sa[0-9]*|xargs -I '{}' sar -u -f {}|awk '/^[0-9]/&&!/^12:00:01|RESTART|CPU/{print "%user: "$4" %system: "$6" %iowait: "$7" %nice: "$5" %idle: "$9}'|sort -nk10|head
cls && ipconfig | findstr -R "[ IPv4 | adapter ]"
egrep -ie "<*HREF=(.*?)>" index.html | awk -F\" '{print $2}' | grep ://
caff <keyid>
2009-02-18 14:09:03
User: raphink
Tags: GPG
-1

Requires: signing-party (on Debian).

Note: you need a working MTA on your machine.

curl queip.tk/ip
alias :q='tput setaf 1; echo >&2 "this is NOT vi(m) :/"; tput sgr0'
2009-12-08 12:59:44
User: sputnick
Functions: alias echo tput
Tags: vim alias vi tput
-1

For vi(m) users :

Add it in your ~/.bashrc

Add an "exit" @ the end if you are masochist ;)

tune2fs -l /dev/XXXX | grep -w ^"Block size:"
2011-02-10 16:39:14
User: ncaio
Functions: grep tune2fs
-1

the result of the command helped a check the Maximum file size and Maximum file system size.

EXT3 Exemple:

Block size; MAX File size; Maximum file system size

1 KiB; 16 GiB ; 2 TiB

2 KiB ; 256 GiB ; 8 TiB

4 KiB ; 2 TiB ; 16 TiB

8 KiB[limits 1]; 2 TiB; 32 TiB