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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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 - 66 results
csv2json() { for file in $@; do python -c "import csv,json,fileinput; print(json.dumps(list(csv.reader(fileinput.input()))))" "$file" 1> "${file%%csv}json"; done; }
2017-06-28 04:28:32
User: snipertyler
Functions: file python
Tags: CSV python json

Based / Inspired by malathion's below command


Is written for python3 and is very easy to use

csv2json *csv will convert all files ending in csv to json

eg csv2json file.csv will output a file to file.json

Validity of json tested in python3 and below site


python -c "import csv,json;print json.dumps(list(csv.reader(open('csv_file.csv'))))"
2017-05-17 19:35:53
User: malathion
Functions: python
Tags: CSV python json

Replace 'csv_file.csv' with your filename.

pacman -Ss python | paste - - | grep --color=always -e '/python' | less -R
2016-01-25 14:29:31
User: hute37
Functions: grep less paste python
Tags: less paste pacman

Alternative1 (grep support):

pacman -Ss python | paste - - | grep --color=always -e '/python' | less -R

Alternative2 (eye-candy, no grep):

pacman --color=always -Ss "python" | paste - - | less -R

in ~/.bashrc:

pkg-grep() { pacman -Ss "$1" | paste - - | grep --color=always -e "${2:-$1}" | less -R ; }

pkg-search() { pacman --color=always -Ss "python" | paste - - | less -R; }

python -c "import requests; from bs4 import BeautifulSoup; print '\n'.join([cmd.text for cmd in BeautifulSoup(requests.get('http://www.commandlinefu.com/commands/by/${USER}').content, 'html.parser').find_all('div','command')])"
2015-08-22 21:32:36
User: funky
Functions: python

This utilizes the Requests and BeautifulSoup libraries in Python to retrieve a user page on commandlinefu, parse it (error-tolerant) and extract all the lines of the following format:

gzip *

To print them, a list comprehension is used to iterate over the values, and join() is called on a newline character.

python -c 'import sys, yaml, json; yaml.safe_dump(json.load(sys.stdin), sys.stdout, allow_unicode=True)' < foo.json > foo.yaml
2015-01-20 15:58:29
User: renoirb
Functions: python

If you tried the other Python version of Convert JSON to YAML and you end up with lines that has "!!python/unicode", this version of the command is for you.

python -c "import pip; print(' '.join([x.project_name for x in pip.get_installed_distributions()]))" | xargs sudo pip install -U
python -c 'import random; print "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*-_=+") for i in range(10)])'
2014-06-10 14:30:02
User: jouz
Functions: python

for i rang(10) = length of the password

random.choice("abcdefghijklmnopqrstuvwxyz...") = char allowed into the password

Thanks Python/Django FAQ's.

find . -name '*.mp3' | sort | while read -r mp3; do echo -e "<h3>$mp3</h3>\n<audio controls src=\"$mp3\"></audio>"; done > index.html; python -m http.server
2014-03-24 15:01:49
User: hendry
Functions: echo find python read sort
Tags: audio browser

I tried a few curses based mp3 players for playing back choir practice songs for my wife.

Unfortunately none of the ones I tried were capable of scrubbing a track.

Firefox saves the day.

echo "select a, b, c from table where a = 3;"| python -c "import sys;import sqlparse;print sqlparse.format(sys.stdin.read(), reindent=True, keyword_case='upper')"
2014-02-21 23:17:15
User: hide1713
Functions: echo python

You need to apt-get install python-sqlparse. This command simply formats a sql query and prints it out. It is very useful when you want to move a sql query from commandline to a shell script. Everything is done locally, so you don't need to worry about copying sql query to external websites.

curl -s http://www.census.gov/popclock/data/population/world | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["world"]["population"]'
python -c "a='$(ps -u luke | grep Viber.exe)';b= a.split(' ')[1];import os;os.system('cpulimit -l 1 -p '+b)"
cat foo.json | python -mjson.tool
2013-05-06 20:11:05
User: jeffgage
Functions: cat python
Tags: json

For situations where you keep JSON in a VCS and you want your diffs to be sane, such as within a Chef configuration repo.

python -c 'import sys, yaml, json; yaml.safe_dump(json.load(sys.stdin), sys.stdout, default_flow_style=False)' < file.json > file.yaml
2013-04-24 00:31:39
User: tebeka
Functions: python
Tags: python json yaml

Convert JSON to YAML.

Note that you'll need to have PyYaml installed.

python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < file.yaml > file.json
2013-04-24 00:28:55
User: tebeka
Functions: python
Tags: python json yaml

Converts YAML file to JSON.

Note that you'll need to install PyYAML. Also some YAML data types (like dates) are not supported by JSON).

python -c "help('modules')"
FILE='mp3.list';LNNO=`wc -l $FILE|cut -d' ' -f 1`;LIST=( `cat $FILE` );for((;;)) do SEED=$((RANDOM % $LNNO));RNNO=$(python -c "print int('`openssl rand -rand ${LIST[$SEED]} 8 -hex 2>/dev/null`', 16) % $LNNO");mplayer ${LIST[$RNNO]};sleep 2s; done
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 18 | head -1 | python -c "import sys,crypt; stdin=sys.stdin.readline().rstrip('\n'); print stdin;print crypt.crypt(stdin)"
2012-11-09 00:40:22
User: cnyg
Functions: cat fold head python tr

Generate a 18 character password from character set a-zA-Z0-9 from /dev/urandom, pipe the output to Python which prints the password on standard out and in crypt sha512 form.

python -m SimpleHTTPServer 8000 &; sudo localtunnel -k ~/.ssh/id_rsa.pub 8000
2012-10-30 17:52:14
User: dzup
Functions: python sudo

you need ruby gems and localtunnel, further instruction on their website

for ubuntu precise, just intall ...

sudo apt-get install ruby ruby1.8-dev rubygems1.8 libopenssl-ruby

sudo gem install localtunnel

ssh-keygen -t rsa

python -m SimpleHTTPServer 8000

sudo localtunnel -k ~/.ssh/id_rsa.pub 8000

python -c 'import googl; print googl.Googl("<your_google_api_key>").shorten("'$someurl'")[u"id"]'
2012-05-31 17:14:17
User: shr386
Functions: python

(1) required: python-googl ( install by: pip install python-googl )

(2) get from google API console https://code.google.com/apis/console/

tail -F /var/log/nginx/access.log | python -c 'exec("import sys,time\nl=0\ne=int(time.time())\nfor line in sys.stdin:\n\tt = int(time.time())\n\tl += 1\n\tif t > e:\n\t\te = t\n\t\tprint l\n\t\tl = 0")'
2012-05-15 21:56:46
User: pykler
Functions: python tail

Realtime lines per second in a log file using python ... identical to perl version, except python is much better :)

python -c 'print open("path/to/image.png", "rb").read().encode("base64").replace("\n","")'
2012-04-20 13:50:53
User: leonjh
Functions: python

useful if you are using lots of data URI's in your css files

while read ; do python <script> ; done
2012-02-23 22:29:09
User: Zulu
Functions: python read

Very useful for test a script. After launch this command, you only have to press ENTER for launch your script again. I work with screen and tape ENTER instead of '!!'+ENTER

If you break your script with CTRL-C, it will wait for press ENTER and will re-launch

You can write like it : while read -p "Press ENTER" ; do python ; done

python -c 'print "hello".encode("hex")'
2011-12-13 23:05:17
User: atoponce
Functions: python

You can use "decode()" in a similar manner:

python -c 'print "68656c6c6f".decode("hex")'
python -c 'print hex(1337)'
2011-12-13 22:03:10
User: atoponce
Functions: python

Python is always such much more readable than most shell scripting.

python -c "from uuid import UUID; print UUID('63b726a0-4c59-45e4-af65-bced5d268456').hex;"
2011-11-20 10:35:44
User: mackaz
Functions: python

Remove dashes, also validates if it's a valid UUID (in contrast to simple string-replacement)