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 tagged json from sorted by
Terminal - Commands tagged json - 29 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.

ftagmarks(){ jq -r --arg t "$1" '.children[] as $i|if $i.root == "tagsFolder" then ([$i.children[] as $j|{title: ($j.title), urls: [$j.children[].uri]}]) else empty end|.[] as $k|if ($k.title|contains($t)) then $k.urls else empty end|.[]?' "$2"; }
2016-12-24 15:12:04
User: qwertyroot
Functions: as

# Usage: ftagmarks TAG BOOKMARKS.JSON

ftagmarks Bash ~/.mozilla/firefox/*.default/bookmarkbackups/bookmarks-*.json

Tag can be partial matching, e.g. input 'Bas' or 'ash' will match 'Bash' tag.

# Exact tag matching:

ftagmark(){ jq -r --arg t "$1" '.children[] as $i|if $i.root == "tagsFolder" then ([$i.children[] as $j|{title: ($j.title), urls: [$j.children[].uri]}]) else empty end|.[] as $k|if $k.title == $t then $k.urls else empty end|.[]?' "$2"; }

Usage: ftagmark TAG BOOKMARKS.JSON

# List all tags:

ftagmarkl(){ jq -r '.children[] as $i | if $i.root == "tagsFolder" then $i.children[].title else empty end' "$1"; }

Usage: ftagmarkl BOOKMARKS.JSON

# Requires: `jq` - must have CLI JSON processor


curl -s httpbin.org/ip | jq -r .origin
btc() { echo "1 BTC = $(curl -s https://api.coindesk.com/v1/bpi/currentprice/$1.json | jq .bpi.\"$1\".rate | tr -d \"\"\") $1"; }
2015-09-19 02:49:30
User: benjabean1
Functions: echo

The only pre-requisite is jq (and curl, obviously).

The other version used grep, but jq is much more suited to JSON parsing than that.

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.

catmandu convert JSON --multiline 1 to YAML < file.json > file.yaml
2014-09-29 16:45:24
Tags: perl json yaml

This is based on __unixmonkey73469__ answer. You will need to supply `--multiline 1` option to JSON importer if your .json is multiline (i.e. it was prettyfied)

And you still need catmandu installed via `cpanm Catmandu`

ogr2ogr -f GeoJSON output.geojson input.shp
alias pp='python -mjson.tool|pygmentize -l js'
2014-05-22 10:29:44
User: wires
Functions: alias
Tags: bash json

Leave out pygmentize or `pip install pygments` first.

catmandu convert JSON to YAML < file.json > file.yaml
2014-02-25 08:27:05

You need to install the Catmandu Perl module via `cpanm Catmandu`

ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))' < file.yml > file.json
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.

mv data.{json,yaml}
2013-04-25 07:47:32
User: bunam
Functions: mv
Tags: json yaml

since Mozai said that JSON is a subset of YAML ;)

cat data.json >data.yml
2013-04-25 04:09:58
User: Mozai
Functions: cat
Tags: json yaml

Valid JSON is a subset of YAML; no transformation is necessary; however, YAML has many syntax features that are not valid JSON, so you can't do the reverse as easily.

ruby -ryaml -rjson -e 'puts YAML.dump(JSON.parse(STDIN.read))' < file.json > file.yaml
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).

uniq -c | sed -r 's/([0-9]+)\s(.*)/"\2": \1,/;$s/,/\n}/;1i{'
alias pp='python -mjson.tool | pygmentize -l javascript'
2012-10-16 13:55:38
User: wires
Functions: alias

Uses pygmentize and python to create indented and colorized JSON output

ash prod<tab>
2012-05-12 19:51:02
User: c3w


. a Ruby SSH helper script

. reads a JSON config file to read host, FQDN, user, port, tunnel options

. changes OSX Terminal profiles based on host 'type'


put 'ash' ruby script in your PATH

modify and copy ashrc-dist to ~/.ashrc

configure OSX Terminal profiles, such as "webserver", "development", etc

run "ash myhostname" and away you go!

v.2 will re-attach to a 'screen' named in your ~/.ashrc

js -e 'JSON.stringify({hello:"world"})'
curl -s http://geoiplookup.wikimedia.org/ | python3 -c 'import sys, json, string, webbrowser; webbrowser.open(string.Template("http://maps.google.com/maps?q=$lat,$lon").substitute(json.loads(sys.stdin.read().split("=")[-1])))'
wget -qO - "http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=steering+wheel&sl=en&tl=en&restrict=pr,de&client=te" | sed 's/dict_api\.callbacks.id100.//' | sed 's/,200,null)//'
2011-03-08 15:00:39
User: sairon
Functions: sed wget
wget -qO - "http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=steering+wheel&sl=en&tl=en&restrict=pr,de&client=te"

this does the actual google dictionary query, returns a JSON string encapsulated in some fancy tag

sed 's/dict_api\.callbacks.id100.//'

here we remove the tag beginning

sed 's/,200,null)//'

and here the tag end

There are also some special characters which could cause problems with some JSON parsers, so if you get some errors, this is probably the case (sed is your friend).

I laso like to trim the "webDefinitions" part, because it (sometimes) contains misleading information.

sed 's/\,\"webDefinitions.*//'

(but remember to append a "}" at the end, because the JSON string will be invalid)

The output also contains links to mp3 files with pronounciation.

As of now, this is only usable in the English language. If you choose other than English, you will only get webDefinitions (which are crap).

wget -q -U "Mozilla/5.0" --post-file speech.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=en-us&client=chromium"
2011-03-08 13:39:01
User: sairon
Functions: wget

The FLAC audio must be encoded at 16000Hz sampling rate (SoX is your friend).

Outputs a short JSON string, the actual speech is in the hypotheses->utterance, the accuracy is stored in hypotheses->confidence (ranging from 0 to 1).

Google also accepts audio in some special speex format (audio/x-speex-with-header-byte), which is much smaller in comparison with losless FLAC, but I haven't been able to encode such a sample.

The command is too big to fit here. :( Look at the description for the command, in readable form! :)
2011-01-05 02:45:28
User: hunterm
Functions: at command

Yep, now you can finally google from the command line!

Here's a readable version "for your pleasure"(c):

google() { # search the web using google from the commandline # syntax: google google query=$(echo "$*" | sed "s:%:%25:g;s:&:%26:g;s:+:%2b:g;s:;:%3b:g;s: :+:g") data=$(wget -qO - "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=$query") title=$(echo "$data" | tr '}' '\n' | sed "s/.*,\"titleNoFormatting//;s/\":\"//;s/\",.*//;s/\\u0026/'/g;s/\\\//g;s/#39\;//g;s/'amp;/\&/g" | head -1) url="$(echo "$data" | tr '}' '\n' | sed 's/.*"url":"//;s/".*//' | head -1)" echo "${title}: ${url} | http://www.google.com/search?q=${query}" }

Enjoy :)