bashoneliners.com

Welcome to bashoneliners.com, a curated collection of practical and well-explained Bash one-liners, snippets, tips and tricks. We aim to make each published one-liner to be of high quality: useful, easy to read, follows best practices, with clear, detailed, accurate explanation. These one-liners should help you automate tasks, troubleshoot problems, whether it be in system administration, file management, networking or programming.

Download a URL with cookies set on the command line with curl

curl -b "session=$session" 'https://adventofcode.com/2023/day/18/input'

December 18, 2023bashoneliners

Pretty-print JSON with Python

curl -s 'https://api.github.com/orgs/github/repos' | python -m json.tool

November 15, 2023bashoneliners

Send an HTTP POST request as if submitting an HTML form using curl

curl --data "title=recipe&text=steps123" https://example.com

November 13, 2023bashoneliners

Printing with jq multiple values in CSV or TSV formats

curl -s 'https://api.github.com/orgs/github/repos' | jq -r '.[] | [.id, .name, .stargazers_count] | @csv'

October 13, 2023bashoneliners

Inspect the HTTP headers of a website

curl -I amazon.com

February 8, 2019bashoneliners

Puppet/Bash: test compare json objects.

unless => "client_remote=\"$(curl localhost:9200/_cluster/settings | python -c \"import json,sys;obj=json.load(sys.stdin);print(obj['persistent']['search']['remote'])\")\"; new_remote=\"$( echo $persistent_json | python -c \"import json,sys;obj=json.load(sys.stdin);print(obj['persistent']['search']['remote'])\")\"; [ \"$client_remote\" = \"$new_remote\" ]",

July 27, 2018cjedwa

Big CSV > batches > JSON array > CURL POST data with sleep

cat post-list.csv | split -l 30 - --filter='jq -R . | jq --slurp -c .' | xargs -d "\n" -I % sh -c 'curl -H "Content-Type: application/json" -X POST -d '"'"'{"type":1,"entries":%}'"'"' http://127.0.0.1:8080/purge-something && sleep 30'

March 7, 2018pratham2003

Get the HTTP status code of a URL

curl -Lw '%{http_code}' -s -o /dev/null -I SOME_URL

June 19, 2017bashoneliners

Get a free shell account on a community server

gpg --recv-keys 0xD2C4C74D8FAA96F5 && curl https://hashbang.sh | gpg -o hashbang.sh && less hashbang.sh

March 15, 2015lrvick

Parse nginx statistics output

i=$(curl -s server/nginx_stats); IFS=$'\n'; i=($i); a=${i[0]/Active connections: } && a=${a/ }; r=${i[2]# [0-9]* [0-9]* }; echo "Active: $a, requests: $r"

June 20, 2014azat

Send HTTP POST to a website with a file input field

curl -L -v -F "value=@myfile" "http://domain.tld/whatever.php"

February 15, 2012openiduser14

Check the performance of a script by re-running many times while measuring the running time

for i in {1..10}; do time curl http://localhost:8000 >/dev/null; done 2>&1 | grep real

December 17, 2011bashoneliners