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,621 results
for i in ./*.$1; do mv "$i" `echo $i | tr ' ' '_'`; done for i in ./*.$1; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done for i in ./*.$1; do mv "$i" `echo $i | tr '-' '_'`; done for i in ./*.$1; do mv "$i" `echo $i | tr -s '_' `; done
export PATH=$PATH:`pwd`
2011-02-05 06:29:54
User: YogiBare
Functions: export
-3

This will temporarily add the current directory to your $PATH. Allowing you to execute from that directory for the duration of the session.

function encode4phone() { ffmpeg -acodec libamr_nb -vcodec h263 -i "$1" -s qcif -b 200k -ac 1 -ab 7.4k -ar 8000 "$1.3gp" }
tar cvf - /src | ( cd /dest ; tar xvf - )
2011-09-22 15:35:24
User: a8ksh4
Functions: cd tar
-3

This is how I've done it in the past

echo -e "aa\nbb\ncc\ndd\n123" | sed -e :a -e "/$/N; s/\n/;/; ta"
ps ho command $$
echo $SHELL
tar -zcps <dir> -X <(find <dir> -type f -mtime -<days>) |ssh user@backuphost tar -xzpsC /data/bkup
2009-02-12 22:31:58
User: zb
Functions: find tar
-3

due to bug can not comment

opendiff <file1> <file2>
2009-06-16 03:22:52
User: claytron
-3

This command will open up the two files in FileMerge on OS X. You can also compare two directories.

opendiff directory1 directory2

NOTE: FileMerge is a part of the OS X Developer Tools, available on the install disc.

rsync --daemon --port 9999 --no-detach -v --config .rsyncd.conf
2011-09-22 20:48:31
User: pykler
Functions: rsync
-3

An example config file is placed in the sample output along with the command line call to use it.

The rsync daemon here is setup on the destination, thus requiring the read only = false flag. Also it uses uid and gid of root, change as required.

exec 3<>/dev/tcp/whatismyip.com/80; echo -e "GET /automation/n09230945.asp HTTP/1.0\r\nHost: whatismyip.com\r\n" >&3; a=( $(cat <&3) ); echo ${a[${#a[*]}-1]};
ifconfig -a|grep Bcast:|cut -d\: -f2|awk '{print $1}'
ps -axgu | cut -f1 -d' ' | sort -u
ifconfig -a | awk '/Bcast/{print $2}' | cut -c 5-19
locate searchstring | xargs grep foo
2009-04-16 12:51:24
User: zimon
Functions: grep locate xargs
Tags: grep locate
-3

Greps located files for an expression.

Example greps all LaTeX files for 'foo':

locate *.tex | xargs grep foo

To avoid searching thousands of files with grep it could be usefull to test first how much files are returned by locate:

locate -c *.tex
wget -O gsplitter.crx "https://clients2.google.com/service/update2/crx?response=redirect&x=id%3Dlnlfpoefmdfplomdfppalohfbmlapjjo%26uc%26lang%3Den-US&prod=chrome&prodversion=8.0.552.224" ; google-chrome --load-extension gspliter.crx
2010-12-14 19:12:18
User: strzel_a
Functions: wget
-3

Download Gsplitter extension, and execute it with Chrome !

Or download it here :

https://chrome.google.com/extensions/detail/lnlfpoefmdfplomdfppalohfbmlapjjo

buf () {oldname=$1; if [ "$oldname" != "" ]; then datepart=$(date +%Y-%m-%d); firstpart=`echo $oldname | cut -d "." -f 1`; newname=`echo $oldname | sed s/$firstpart/$firstpart.$datepart/`; cp -i ${oldname} ${newname}; fi }
2010-12-14 19:58:34
User: Seebi
Functions: cp cut date sed
-3

This backup function preserve the file suffix allowing zsh suffix aliases and desktop default actions to work with the backup file too.

egrep '(expr1|expr2)' file
2011-07-14 14:22:11
User: evandrix
Functions: egrep
-3

to find occurances of expr1 OR expr2

accurev stat -M -fl | awk '{print "\"" $0 "\""}' | xargs accurev pop
msiexec.exe /i product.msi /l* c:\folder\LogFileName.txt
apt-get remove `deborphan`
mv file_name.extension ..
2009-03-09 15:35:58
User: takealeft
Functions: mv
-3

cd into the directory that contains the file.

this is just the usual move command but shortcut'd.

say you wanted to move a photo img1.png from ~/photos/holidayphotos into the parent directory which is ~/photos

command would be:

~/photos/holidayphotos$ mv img1.png ..

I use Ubuntu so this'll work in debian but not sure what else.

check(){ power=$(acpi -a) ; if [[ $power == *on-line* ]] ; then echo "supply is on"; else echo "somebody is steeling your laptop"; amixer -c0 set Master 100+ unmute ; mpg123 nuclear-alarm.mp3 ; fi } ;while true; do check ; sleep 2 ; done
2011-12-10 13:42:52
User: hoodie
-3

Checks whether your power supply is still plugged in.

If not it will trigger an alarm at maximum volume.

#Client# cat "The Meters - People Say.mp3" | nc -vv 192.168.1.100 8080; #Server# nc -vv -l -s 192.168.1.100 -p 8080 | mpg123 -v -
2010-01-30 08:50:17
User: Abiden
Functions: cat mpg123
-3

I think I picked this one up from Hak5 (yeah I know.. kinda lame)

<TBD>
2010-12-15 07:48:25
User: chaliyans
-3

Is there a way to print the line BASH is executing without copy+paste the line inside an 'echo' command?