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

Commands using python from sorted by
Terminal - Commands using python - 63 results
python fsrecovery.py -P 0 -f <path-to-instance>/Data.fs <path-to-instance-destination>/Data.fs.packed
curl -s "http://services.digg.com/stories?link=$NEWSURL&appkey=http://www.whatever.com&type=json" | python -m simplejson.tool | grep diggs
python -c 'import this'
python -c "import scapy.all; print [x[4] for x in scapy.all.conf.route.routes if x[2] != '0.0.0.0'][0]"
echo '{"json":"obj"}' | python -m simplejson.tool
2009-05-10 13:58:05
User: azeey
Functions: echo python
Tags: python json
11

You can use a site like http://www.jsonlint.com/ or use the command line to validate your long and complex json data. This is part of the simplejson package for python http://undefined.org/python/#simplejson.

Wrong json expression example:

echo '{ 1.2:3.4}' | python -m simplejson.tool

Expecting property name: line 1 column 2 (char 2)

python -c "import socket; print '\n'.join(socket.gethostbyname_ex(socket.gethostname())[2])"
2009-04-30 16:10:43
User: haivu
Functions: python
Tags: Network python
-6

The socket.gethostname() call returns the host name of the computer. The socket.gethostbyname_ex() call returns a list of three items: The host name, the list of aliases for this host, and a list of IP addresses. Recall that Python?s array starts with index 0, the socket.gethostbyname_ex(?)[2] expression refers to the list of IP addresses. Finally, the print statement prints out the IP addresses, one per line.

python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"
rgx_match() { python -c "import re; print re.search('$1','$2').groups()"; }
2009-02-16 04:07:54
User: jyro
Functions: python
1

One can test their python regex matching using this shell function.

for e.g.

rgx_match "translate\s*\(([0-9-.]+),([0-9-.]+)\)" "translate(162.11517,76.817357)"

('162.11517', '76.817357')

srchpymod() { python -c "import $1; print filter(lambda x: x.find('$2') >= 0, dir($1))"; };
2009-02-16 02:47:13
User: jyro
Functions: python
0

srchpymod

for e.g.

srchpymod cairo Surface

['ImageSurface', 'PDFSurface', 'PSSurface', 'SVGSurface', 'Surface', 'SurfacePattern', 'XlibSurface']

$ python -m pygments -o source.html source.py
2009-02-06 08:00:02
User: antrix
Functions: python
1

You can specify various output formats, theme styles, etc.

python -m pygments -o source.png source.py python -m pygments -o source.rtf source.py

Check available output formats, styles, etc.:

python -m pygments -L

Find pygments module here: http://pygments.org/

python -m smtpd -n -c DebuggingServer localhost:1025
2009-02-05 16:50:44
User: jemerick
Functions: python
69

This command will start a simple SMTP server listening on port 1025 of localhost. This server simply prints to standard output all email headers and the email body.

python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"
2009-02-05 15:43:43
User: anokneemouse
Functions: python
0

Want to show something on your machine to someone over the web? Don't copy it or upload it somewhere. Just run "webshare" and the current directory and everything beneath it will be served from a new web server listening on port 8000. When your pal is finished, hit control-c.

Found at www.shell-fu.org/lister.php?id=54

python -m SimpleHTTPServer