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,859 results
ogr2ogr -f GeoJSON output.geojson input.shp
finfd./ -name logs -type f -size 50
wget -qO- http://whatthecommit.com/index.txt | cowsay
2014-08-26 18:56:06
User: optyler
Functions: wget
1

No need to parse html page, website gives us a txt file :)

sprunge() { curl -F 'sprunge=<-' http://sprunge.us < "${1:-/dev/stdin}"; }
2014-08-26 17:47:31
User: malathion
1

echo "Hello world!" | sprunge # Redirect a stream to a pastebin

sprunge ~/.bashrc # Send a file to a pastebin

dd if=/dev/random count=1 bs=2 2>/dev/null | od -i | awk '{print $2}' | head -1
find . -type d -print0 | while read -d $'\0' dir; do cd "$dir"; echo " process $dir"; find . -maxdepth 1 -name "*.ogg.mp3" -exec rename 's/.ogg.mp3/.mp3/' {} \; ; cd -; done
2014-08-25 11:28:43
Functions: cd echo find read rename
2

This is probably overkill, but I have some issues when the directories have spaces in their names.

The

find . -type d -print0 | while read -d $'\0' dir; do xxx; done

loops over all the subdirectories in this place, ignoring the white spaces (to some extend).

cd "$dir"; echo " process $dir"; cd -;

goes to the directory and back. It also prints some info to check the progress.

find . -maxdepth 1 -name "*.ogg.mp3" -exec rename 's/.ogg.mp3/.mp3/' {} \;

renames the file within the current directory.

The whole should work with directories and file names that include white spaces.

curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"This is the title of the message","message":"This is the body of the message"},"id":1}' http://i3c.pla.lcl:8080/jsonrpc
2014-08-24 21:49:13
User: PLA
0

Send a text message to an Kodi (XBMC) device. Uses curl to post a JSON request to the Kodi JSON-RPC API.

ffmpeg -i input.mpg -deinterlace -pix_fmt yuv420p -vcodec libx264 -preset slow -vprofile high -trellis 2 -crf 20 -ac 2 -ab 192k -f mp4 -ss 5:00.000 -to 25:00.000 output.avi
Pasion_por_Debian_1_by_arthecrow
netstat -anp | grep ":<port>"
tasklist /nh /fi "imagename eq notepad.exe" | findstr /i "notepad.exe" >nul && (echo Notepad is running)|| (Echo Notepad is not running)
2014-08-22 00:52:19
Functions: echo
0

There are many ways to do it on *nix. But on Windows, it's a bit convoluted.

I use the above command expression in a batch file to check if a process is running already before running it again. I use this is a batch file I created to switch between 2 different versions of PowerBuilder (PB). I wanted to make sure, one version of PB is not running, before letting the user to switch, hence this check. (replace notepad.exe with PB125.exe above).

/nh means no header, /fi means filter. We are filtering for Notepad.exe only above. Then, we take that and look for Notepad.exe using a FindStr command. It will still work, even if we don't have those 2 flags, but it makes finding the right program quicker.

&& and || are part of the conditional expressions see here: http://www.robvanderwoude.com/condexec.php. We use these to print for the IF...ELSE condition.

>nul is the equivalent of Unix /dev/null

Rest is self explanatory, I think.

cat /var/log/syslog | grep score= | awk '{print $15}' | more
tail -1f /var/opt/fds/logs/TraceEventLogFile.txt.0 | grep <msisdn> | tee <test-case-id>.trace | tr '|' '\n'
2014-08-21 19:29:07
User: neomefistox
Functions: grep tail tee tr
0

This command allows to follow up a trace on SDP (CS5.2), at the same time as the trace records are stored in the file with "raw" format.

Trace files in native format are useful to filter the records before to translation from '|' to '\n'.

Example:

grep -v OP_GET <raw-records>.trace | tr '|' '\n'
rsync -av -f"+ */" -f"- *" [source] [dest]
sudo pip install rainbowstream && rainbowstream -iot
2014-08-20 06:45:16
User: DTVD
Functions: install sudo
0

Rainbow Stream is a smart and nice Twitter client on terminal.

Almost everything you can do with a GUI application can be done, even viewing an image.

- Tab-autocomplete, history browsing

- Beautiful built-in themes and custom configuration support

- Tweet's images directly on your terminal.

ffmpeg -acodec copy -vcodec copy -ss 00:05:00 -t 00:20:00 -i file.mp4 file_cropped.mp4
curl -L https://gist.github.com/westonruter/ea038141e46e017d280b/download | tar -xvz --strip-components=1
2014-08-19 22:19:44
User: westonruter
Functions: tar
Tags: gist
0

https://twitter.com/westonruter/status/501855721172922369

rm -rf directoryname
xrandr --output DVI-I-2 --mode 1920x1080 --output HDMI-0 --off --output DVI-I-1 --mode 1280x1024 --pos 1920x0
du -sm *| sort -nr | awk '{ size=4+5*int($1/5); a[size]++ }; END { print "size(from->to) number graph"; for(i in a){ printf("%d %d ",i,a[i]) ; hist=a[i]; while(hist>0){printf("#") ; hist=hist-5} ; printf("\n")}}'
2014-08-19 14:43:20
User: higuita
Functions: awk du sort
Tags: awk
0

This command makes a small graph with the histogram of size blocks (5MB in this example), not individual files. Fine tune the 4+5*int($1/5) block for your own size jumps : jump-1+jump*($1/jump)

Also in the hist=hist-5 part, tune for bigger or smaller graphs

getent hosts <host>
pwgen -CsyN 1 16
tr -dc '\x15-\x7e' < /dev/urandom| head -c 16 | paste
echo "bored of the awaiting moderation"
xclip -selection clipboard -o -t text/html | pandoc -f html -t markdown_github -
2014-08-18 20:47:46
User: keymon
2

I always wanted to be able to copy formatted HTML, like from emails, on trello cards or READMEs... but the formatting is always wrong... But from this two links:

* https://jeremywsherman.com/blog/2012/02/08/pasting-html-into-markdown/

* http://stackoverflow.com/questions/3261379/getting-html-source-or-rich-text-from-the-x-clipboard

For instance, to to copy an formatted email to a trello card, just:

1. Select the email body

2. run: xclip -selection clipboard -o -t text/html | pandoc -f html -t markdown_github - | xclip -i -t text/plain

3. Paste in your trello card

4. Profit!

8-)