From 5414d495a4f5e6f09beafb77e3630a46866be463 Mon Sep 17 00:00:00 2001 From: ivuorinen Date: Sun, 18 May 2025 00:21:47 +0000 Subject: [PATCH] Update cheatsheets --- tldr/awk | 2 ++ tldr/gawk | 44 +++++++++++++++++++++++++++++++++++++++++ tldr/less-than | 6 +++++- tldr/linux/decode-dimms | 17 ++++++++++++++++ tldr/linux/kde-builder | 2 +- tldr/linux/mkfs.btrfs | 4 ++++ tldr/mise | 6 +++++- tldr/xh | 20 +++++++++++-------- 8 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 tldr/gawk create mode 100644 tldr/linux/decode-dimms diff --git a/tldr/awk b/tldr/awk index ed555eee..2f9e4e8e 100644 --- a/tldr/awk +++ b/tldr/awk @@ -6,6 +6,8 @@ source: https://github.com/tldr-pages/tldr.git # awk > A versatile programming language for working on files. +> Note: Different implementations of AWK often make this a symlink of their binary. +> See also: `gawk`. > More information: . - Print the fifth column (a.k.a. field) in a space-separated file: diff --git a/tldr/gawk b/tldr/gawk new file mode 100644 index 00000000..90aaba39 --- /dev/null +++ b/tldr/gawk @@ -0,0 +1,44 @@ +--- +syntax: markdown +tags: [tldr, common] +source: https://github.com/tldr-pages/tldr.git +--- +# gawk + +> GNU version of awk, a versatile programming language for working on files. +> See also: `awk`. +> More information: . + +- Print the fifth column (a.k.a. field) in a space-separated file: + +`gawk '{print $5}' {{path/to/file}}` + +- Print the second column of the lines containing "foo" in a space-separated file: + +`gawk '/{{foo}}/ {print $2}' {{path/to/file}}` + +- Print the last column of each line in a file, using a comma (instead of space) as a field separator: + +`gawk {{[-F|--field-separator]}} ',' '{print $NF}' {{path/to/file}}` + +- Sum the values in the first column of a file and print the total: + +`gawk '{s+=$1} END {print s}' {{path/to/file}}` + +- Print every third line starting from the first line: + +`gawk 'NR%3==1' {{path/to/file}}` + +- Print different values based on conditions: + +`gawk '{if ($1 == "foo") print "Exact match foo"; else if ($1 ~ "bar") print "Partial match bar"; else print "Baz"}' {{path/to/file}}` + +- Print all the lines which the 10th column value is between a min and a max: + +`gawk '($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): + +`gawk 'BEGIN {FS=":";printf "%-20s %6s %25s +", "Name", "UID", "Shell"} $4 >= 1000 {printf "%-20s %6d %25s +", $1, $4, $7}' /etc/passwd` diff --git a/tldr/less-than b/tldr/less-than index 0638a3af..d5175062 100644 --- a/tldr/less-than +++ b/tldr/less-than @@ -14,7 +14,7 @@ source: https://github.com/tldr-pages/tldr.git - Create a here document and pass that into `stdin` (requires a multiline command): -`{{command}} << {{EOF}} {{multiline_data}} {{EOF}}` +`{{command}} << {{EOF}} {{multiline_text}} {{EOF}}` - Create a here string and pass that into `stdin` (achieves the same effect as `echo string |`): @@ -31,3 +31,7 @@ source: https://github.com/tldr-pages/tldr.git - Disregard leading tabs (good for scripts with indentation but does not work for spaces): `cat <<- {{EOF}} > {{path/to/file.txt}} {{multiline_data}} {{EOF}}` + +- Pass command output to a program as a file descriptor: + +`diff <({{command1}}) <({{command2}})` diff --git a/tldr/linux/decode-dimms b/tldr/linux/decode-dimms new file mode 100644 index 00000000..81c2173b --- /dev/null +++ b/tldr/linux/decode-dimms @@ -0,0 +1,17 @@ +--- +syntax: markdown +tags: [tldr, linux] +source: https://github.com/tldr-pages/tldr.git +--- +# decode-dimms + +> Decode RAM data. +> More information: . + +- Display DIMM information: + +`decode-dimms` + +- Display help: + +`decode-dimms {{[-h|--help]}}` diff --git a/tldr/linux/kde-builder b/tldr/linux/kde-builder index b30b7034..6f69bee6 100644 --- a/tldr/linux/kde-builder +++ b/tldr/linux/kde-builder @@ -13,7 +13,7 @@ source: https://github.com/tldr-pages/tldr.git `kde-builder --initial-setup` -- Compile a KDE component and its dependencies from the source: +- Compile a KDE component and its dependencies from the source (use `workspace` to compile Plasma desktop): `kde-builder {{component_name}}` diff --git a/tldr/linux/mkfs.btrfs b/tldr/linux/mkfs.btrfs index cfabb36d..0e33dc28 100644 --- a/tldr/linux/mkfs.btrfs +++ b/tldr/linux/mkfs.btrfs @@ -20,3 +20,7 @@ source: https://github.com/tldr-pages/tldr.git - Set a label for the filesystem: `sudo mkfs.btrfs {{[-L|--label]}} "{{label}}" {{/dev/sdX /dev/sdY ...}}` + +- Overwrite existing filesystem if one is detected: + +`sudo mkfs.btrfs {{[-f|--force]}} {{/dev/sdX}}` diff --git a/tldr/mise b/tldr/mise index ee4ed3e9..d26ce385 100644 --- a/tldr/mise +++ b/tldr/mise @@ -5,7 +5,7 @@ source: https://github.com/tldr-pages/tldr.git --- # mise -> Manage versions of different packages. +> Manage language runtimes like Node.js, Python, Ruby, Go, Java, etc and various tools. > More information: . - List all available plugins: @@ -35,3 +35,7 @@ source: https://github.com/tldr-pages/tldr.git - Set environment variable in configuration: `mise set {{variable}}={{value}}` + +- Pass plugin options: + +`mise use {{name}}\[{{option1}}={{option1_value}},{{option2}}={{option2_value}}\]@{{version}}` diff --git a/tldr/xh b/tldr/xh index b0793d70..70ef2418 100644 --- a/tldr/xh +++ b/tldr/xh @@ -10,26 +10,30 @@ source: https://github.com/tldr-pages/tldr.git > See also: `http`, `curl`. > More information: . -- Send a GET request: +- Send a GET request (shows response headers and content): -`xh {{httpbin.org/get}}` +`xh {{https://postman-echo.com/get}}` - Send a POST request with a JSON body (key-value pairs are added to a top-level JSON object - e.g. `{"name": "john", "age": 25}`): -`xh post {{httpbin.org/post}} {{name=john}} {{age:=25}}` +`xh post {{https://postman-echo.com/post}} {{name=john}} {{age=25}}` -- Send a GET request with query parameters (e.g. `first_param=5&second_param=true`): +- Send a GET request with query parameters (e.g. `https://postman-echo.com/response-headers?foo1=bar1&foo2=bar2`): -`xh get {{httpbin.org/get}} {{first_param==5}} {{second_param==true}}` +`xh get {{https://postman-echo.com/response-headers}} {{foo1==bar1}} {{foo2==bar2}}` - Send a GET request with a custom header: -`xh get {{httpbin.org/get}} {{header-name:header-value}}` +`xh get {{https://postman-echo.com}} {{header-name:header-value}}` - Make a GET request and save the response body to a file: -`xh --download {{httpbin.org/json}} --output {{path/to/file}}` +`xh {{[-d|--download]}} {{https://example.com}} {{[-o|--output]}} {{path/to/file}}` + +- Construct a request but do not send it (similar to a dry-run): + +`xh --offline {{get|delete|...}} {{https://example.com}}` - Show equivalent `curl` command (this will not send any request): -`xh --{{curl|curl-long}} {{--follow --verbose get http://example.com user-agent:curl}}` +`xh --{{curl|curl-long}} {{--follow --verbose get https://example.com user-agent:curl}}`