Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux:nice-to-know [2018/01/06 14:10] – michael | linux:nice-to-know [2019/05/06 17:33] (current) – michael | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Nice to know Stuff ====== | ====== Nice to know Stuff ====== | ||
- | ---- | ||
<WRAP center round box 100%> | <WRAP center round box 100%> | ||
Line 94: | Line 93: | ||
Here, we match /sda3, then as many characters as possible until we find a stretch of numbers (\d+) which is followed by one or more spaces (\s+), then one or more numbers (\d+) and a %. The foo(?=bar) construct is a positive lookahead, it allows you to search for the string foo only if it is followed by the string bar. The \K is a PCRE trick that means " | Here, we match /sda3, then as many characters as possible until we find a stretch of numbers (\d+) which is followed by one or more spaces (\s+), then one or more numbers (\d+) and a %. The foo(?=bar) construct is a positive lookahead, it allows you to search for the string foo only if it is followed by the string bar. The \K is a PCRE trick that means " | ||
- | Without -P, things are trickier. You would need multiple passes. For example: | + | ''< |
- | df | grep -o '/ | + | < |
</ | </ | ||
+ | ---- | ||
+ | <WRAP center round box 100%> | ||
+ | ''< | ||
+ | To split text on whitespace you can use grep. There’s an infinite amount of ways to do this. This is one of them. | ||
+ | |||
+ | < | ||
+ | |||
+ | <sxh plain; gutter: false; highlight: [1]> | ||
+ | # echo ' | ||
+ | string | ||
+ | --with | ||
+ | ### | ||
+ | 0f | ||
+ | ::outputs | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | <WRAP center round box 100%> | ||
+ | ''< | ||
+ | |||
+ | Make curl get the contents of a URL and write to file, but only write to file if the response is successful: | ||
+ | |||
+ | < | ||
+ | |||
+ | * -s keeps curl quiet by hiding progress meter and error messages | ||
+ | * -S shows an error message if it fails (stderr) | ||
+ | * -f Fail silently (no output at all) on server errors, keeping stdout clean | ||
+ | * -o specifies an output file | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | <WRAP center round box 100%> | ||
+ | ''< | ||
+ | |||
+ | I use this to get a live video stream from my Raspberry Pi with Camera attached | ||
+ | |||
+ | Execute this on the Pi, where TARGET_IP is my local computer where I will watch the stream, and PORT is an arbitrary port number. | ||
+ | |||
+ | < | ||
+ | |||
+ | Execute this on the local computer where you will watch the video stream | ||
+ | |||
+ | < | ||
+ | |||
+ | ---- | ||
+ | |||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | <WRAP center round box 100%> | ||
+ | ''< | ||
+ | |||
+ | '' | ||
+ | |||
+ | <sxh plain; gutter: false;> | ||
+ | genpasswd() { | ||
+ | tr -dc A-Za-z0-9 < / | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Where 36 is default length if no parameter is given | ||
+ | |||
+ | ---- | ||
+ | |||
+ | **Usage**: | ||
+ | |||
+ | < | ||
+ | GVQ3ZHqrBRDzB1QwASA9uk6YsZPto2GWeRWR | ||
+ | |||
+ | # genpasswd 7 | ||
+ | qvPWx7N</ | ||
+ | </ | ||