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.

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:



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!

Top Tags



Commands using python from sorted by
Terminal - Commands using python - 64 results
python -c "import sys;print (sys.byteorder) + ' endian'"
python -ic "from __future__ import division; from math import *; from random import *"
2011-10-24 19:47:27
User: fpunktk
Functions: python

This opens a python command line. You can use math and random and float-division is enabled (without appending .0 to integers). I just don't know how to specify a standard precision.

python -c 'p="SeCuR3PwD";import hashlib as h;s=h.md5(p).hexdigest()[:2];pw=h.md5(s+p).hexdigest();print pw+":"+s;'
2011-10-16 18:49:08
User: Xiol
Functions: as python

ZenCart uses a MD5 with a salt to secure its passwords. If you need to forcibly change someone's password to a known value within the database, this one-liner can generate the password. Change the value of 'p' to the password you want.

python -c'for i in range(1,101):print"FizzBuzz"[i*i%3*4:8--i**4%5]or i'
2011-10-12 21:15:35
User: atoponce
Functions: python

A common programming question for interviewers to ask potential job candidates is to code "FizzBuzz". That is, if a number is divisible by 3, then it should display "Fizz". If a number is divisible by 5, it should display "Buzz". If it is divisible by both, then it should display "FizzBuzz". Otherwise, display the current number between 1 and 100.

python -m SimpleHTTPServer
2011-08-29 03:19:26
Functions: python
Tags: python

This works on all versions of python 2.X.

Tested on Linux and bundled python versions on Mac OSX and Solaris / UNIX

Note: Serves globally on port 8000.

Ctrl+c to stop.

Don't start the server and leave it on a internet connected machine. :)

python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
python -m SimpleHTTPServer
2011-02-12 11:40:56
User: soissons
Functions: python

"this command line isn't mine but i find it very useful" ^^

This one-liner starts a dedicated server hosting (web server) on port 8000 with the contents of current directory on all the interfaces (address, not just localhost. If you have "index.html" or "index.htm" files, it will serve those, otherwise it will list the contents of the currently working directory.

It works because python comes with a standard module called SimpleHTTPServer. The -m argument makes python to search for a module named SimpleHTTPServer.py in all the possible system locations (listed in sys.path and $PYTHONPATH shell variable). Once found, it executes it as a script. If you look at the source code of this module, you'll find that this module tests if it's run as a script if __name__ == '__main__', and if it is, it runs the test() method that makes it run a web server in the current directory.

python -c "print 'this is a test'.title()"
python -m http.server
2010-12-17 12:52:45
User: Alanceil
Functions: python

In Python version 3, the module was merged into http.server. Gentlemen, change your aliases.

python -c "from itertools import imap; from random import randint; print ':'.join(['%02x'%x for x in imap(lambda x:randint(0,255), range(6))])"
python -c 'import datetime; print(datetime.date.today().isocalendar()[1])'
calc() { python -c "from math import *; print $1"; }
2010-10-07 08:26:39
User: asmaier
Functions: python

This function defines a command line calculator that handles everything pythons math module can handle, e.g. trigonometric functions, sqrt, log, erf, ... (see http://docs.python.org/library/math.html). It even knows about the constants pi and e.

python -c $(echo -e 'import py_compile\npy_compile.compile("/path/to/script.py")');
python -c "print 1+1"
$ python -u script.py
2010-05-20 17:53:47
User: recursiverse
Functions: python

You have a python script that slowly prints output, you want to pipe the output to grep or tee, and you are impatient and want to watch the results right away. Rather than modify your script (making it slightly less efficient), use the -u option to have the output unbuffered.

utime(){ python -c "import time; print(time.strftime('%a %b %d %H:%M:%S %Y', time.localtime($1)))"; }
! python %
python -c 'print "-"*50'
2010-03-25 11:09:30
User: funky
Functions: python

essentially the ruby one, but perhaps has a larger installed base

curl -s "http://feeds.delicious.com/v2/json?count=5" | python -m json.tool | less -R
2010-03-24 09:15:12
User: keimlink
Functions: less python

Validates and pretty-prints the content fetched from the URL.

python -c "import platform; print platform.node()"
python -c 'import sys,csv; c = csv.reader(sys.stdin); [sys.stdout.write("^M".join(map(repr,r))+"\n") for r in c];' <tmp/test.csv | column -s '^M' -t
2010-02-01 14:57:25
User: pykler
Functions: c++ column python
Tags: CSV

Will handle pretty much all types of CSV Files.

The ^M character is typed on the command line using Ctrl-V Ctrl-M and can be replaced with any character that does not appear inside the CSV.

Tips for simpler CSV files:

* If newlines are not placed within a csv cell then you can replace `map(repr, r)` with r

python -c 'print "-" * 50'
python -c "import socket; s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.connect(('google.com', 80)); print s.getsockname()[0]"
2009-12-29 19:17:03
User: whiteinge
Functions: python

Requires Python; doesn't require a specific server to return your IP.

gem list --local | python -c "import sys;import re;l=sys.stdin.readlines();x=['config.gem \"'+line[:-1][:line.index(' ')] + '\" , ' +line[:-1][line.index(' '):].replace('(',':version => \"').replace(')','')+'\"' for line in l];print '\n'.join(x)"
gem list --local | python -c "import sys;import re;l=sys.stdin.readlines();x=['config.gem :'+line[:-1][:line.index(' ')] + ' , ' +line[:-1][line.index(' '):].replace('(',':version => ').replace(')','') for line in l];print '\n'.join(x)"