From 4f0d9efa90f8ae266fe4ff6a15bb669d97cdab21 Mon Sep 17 00:00:00 2001 From: ivuorinen Date: Mon, 26 Aug 2024 00:15:54 +0000 Subject: [PATCH] Update cheatsheets --- tldr/awk | 10 ++++++---- tldr/http | 36 ++++++++++++++++++++---------------- tldr/httpie | 37 +++++++++---------------------------- 3 files changed, 35 insertions(+), 48 deletions(-) diff --git a/tldr/awk b/tldr/awk index c9086547..ed555eee 100644 --- a/tldr/awk +++ b/tldr/awk @@ -32,10 +32,12 @@ source: https://github.com/tldr-pages/tldr.git `awk '{if ($1 == "foo") print "Exact match foo"; else if ($1 ~ "bar") print "Partial match bar"; else print "Baz"}' {{path/to/file}}` -- Print all lines where the 10th column value equals the specified value: - -`awk '($10 == {{value}})'` - - Print all the lines which the 10th column value is between a min and a max: `awk '($10 >= {{min_value}} && $10 <= {{max_value}})'` + +- Print table of users with UID >=1000 with header and formatted output, using colon as separator (`%-20s` mean: 20 left-align string characters, `%6s` means: 6 right-align string characters): + +`awk 'BEGIN {FS=":";printf "%-20s %6s %25s +", "Name", "UID", "Shell"} $4 >= 1000 {printf "%-20s %6d %25s +", $1, $4, $7}' /etc/passwd` diff --git a/tldr/http b/tldr/http index a536e1dc..c46e2a05 100644 --- a/tldr/http +++ b/tldr/http @@ -5,33 +5,37 @@ source: https://github.com/tldr-pages/tldr.git --- # http -> HTTPie: HTTP client, aims to be easier to use than cURL. -> More information: . +> HTTPie: an HTTP client designed for testing, debugging, and generally interacting with APIs & HTTP servers. +> More information: . -- Download a URL to a file: +- Make a simple GET request (shows response header and content): -`http --download {{example.org}}` +`http {{https://example.org}}` -- Send form-encoded data: +- Print specific output content (`H`: request headers, `B`: request body, `h`: response headers, `b`: response body, `m`: response metadata): -`http --form {{example.org}} {{name='bob'}} {{profile_picture@'bob.png'}}` +`http --print {{H|B|h|b|m|Hh|Hhb|...}} {{https://example.com}}` -- Send JSON object: +- Specify the HTTP method when sending a request: -`http {{example.org}} {{name='bob'}}` +`http {{GET|POST|HEAD|PUT|PATCH|DELETE|...}} {{https://example.com}}` -- Specify an HTTP method: +- Follow any `3xx` redirects and specify additional headers in a request: -`http {{HEAD}} {{example.org}}` +`http {{--follow|-F}} {{https://example.com}} {{'User-Agent: Mozilla/5.0' 'Accept-Encoding: gzip'}}` -- Include an extra header: +- Authenticate to a server using different authentication methods: -`http {{example.org}} {{X-MyHeader:123}}` +`http --auth {{username:password|token}} --auth-type {{basic|digest|bearer}} {{GET|POST|...}} {{https://example.com/auth}}` -- Pass a username and password for server authentication: +- Construct a request but do not send it (similar to a dry-run): -`http --auth {{username:password}} {{example.org}}` +`http --offline {{GET|DELETE|...}} {{https://example.com}}` -- Specify raw request body via `stdin`: +- Use named sessions for persistent custom headers, auth credentials and cookies: -`cat {{data.txt}} | http PUT {{example.org}}` +`http --session {{session_name|path/to/session.json}} {{--auth username:password https://example.com/auth API-KEY:xxx}}` + +- Upload a file to a form (the example below assumes form field is ``): + +`http --form {{POST}} {{https://example.com/upload}} {{cv@path/to/file}}` diff --git a/tldr/httpie b/tldr/httpie index 5a83512b..1be9d50a 100644 --- a/tldr/httpie +++ b/tldr/httpie @@ -5,37 +5,18 @@ source: https://github.com/tldr-pages/tldr.git --- # httpie -> A user friendly HTTP tool. -> More information: . +> Management interface for HTTPie. +> See also: `http`, the tool itself. +> More information: . -- Send a GET request (default method with no request data): +- Check updates for `http`: -`http {{https://example.com}}` +`httpie cli check-updates` -- Send a POST request (default method with request data): +- List installed `http` plugins: -`http {{https://example.com}} {{hello=World}}` +`httpie cli plugins list` -- Send a POST request with redirected input: +- Install/upgrade/uninstall plugins: -`http {{https://example.com}} < {{file.json}}` - -- Send a PUT request with a given JSON body: - -`http PUT {{https://example.com/todos/7}} {{hello=world}}` - -- Send a DELETE request with a given request header: - -`http DELETE {{https://example.com/todos/7}} {{API-Key:foo}}` - -- Show the whole HTTP exchange (both request and response): - -`http -v {{https://example.com}}` - -- Download a file: - -`http --download {{https://example.com}}` - -- Follow redirects and show intermediary requests and responses: - -`http --follow --all {{https://example.com}}` +`httpie cli plugins {{install|upgrade|uninstall}} {{plugin_name}}`