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
dig google.com
2009-08-28 04:32:52
User: unixbhaskar
Functions: dig
Tags: dns
-1

It is a much better tool then nslookup for getting information about the any site.It has got better capability too.For reverse information please use the switch "-x" and the ip address.

find . -maxdepth 1 -type f -mtime +60 -ls
grep -rnA 10 TODO *
2011-09-28 16:26:14
User: blockcipher
Functions: grep
Tags: grep
-1

This will recursively go through every file under the current directory showing all lines containing "TODO" as well as 10 lines after it. The output will be marked with line numbers to make it easier to find where the TODO is in the actual file.

startx -- :1
2009-02-13 17:22:13
User: sudo
-1

Just tape:

sudo -s

your passwd

startx -- :1

airmon-ng start <interface> <channel>
2009-02-18 11:46:36
User: jie
-1

First you need to instal aircrack-ng

Use this command if you need to put your wireless card into monitor mode.

interface = wlan0 || wifi0 || ath0 et ceatera...

channel = 6, 11, 10, 9 et ceatera

evince "$(find -name 'NameOfPdf.pdf')"
2010-04-04 20:55:51
User: RBerenguel
-1

This assumes there is only one result. Either tail your search for one result or add | head -n 1 before the closing bracket. You can also use locate instead of find, if you have locate installed and updated

setlocal enabledelayedexpansion
2010-08-10 12:26:43
User: Marco
-1

Usually the MS-DOS cmd.exe processes in the whole FOR loop as one command and expands each var like %varname% in before (except the loop var of course).

This command enables expansion of other vars than only the loop var during the FOR loop. The syntax of the var to expand is then !varname! inside the FOR loop.

Use command

endlocal

to end the setlocal command.

E.g. (only works from batch files, not from commandline directly):

@echo off

setlocal enabledelayedexpansion

FOR %%A IN (*) DO (

set file=%%A

echo !file!

)

endlocal

for x in *s.yml; do mv $x `echo $x | sed 's/s\.yml/\.yml/'`; done
2009-03-10 17:51:19
Functions: mv sed
-1

Jan Nelson from Grockit came up with this for us when we needed to rename all of our fixtures.

/sbin/ifconfig | awk -F'[ :]+' '/inet addr/{print $4}'
2009-07-21 14:18:17
User: inof
Functions: awk
-1

That one works on Linux. On BSD and Solaris, the ifconfig output is much easier to parse:

/sbin/ifconfig -a | awk '/inet/{print $2}'
grep $'\t' file.txt
find ~/.thunderbird/*.default/ -name *.msf -print0 | xargs --no-run-if-empty -0 rm;
find . -name .svn -type d -exec rm -rf {} \;
2010-12-15 18:51:08
Functions: find rm
-1

Removing .svn directories without a pipe

dc -e '6k2vp'
mkdir -p temp && for f in *.pdf ; do qpdf --password=YOURPASSWORDHERE --decrypt "$f" "temp/$f"; done && mv temp/* . && rm -rf temp
2013-06-25 18:41:51
Functions: mkdir mv rm
-1

Replace YOURPASSWORDHERE with the pdf password. [qpdf needed]

#11671
/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