Michele Cereda
2023-06-17 19:06:49 +02:00
parent ec6b88893a
commit 1e350029ce
7 changed files with 245 additions and 5 deletions

44
knowledge base/cmp.md Normal file
View File

@@ -0,0 +1,44 @@
# `cmp`
Compares two files byte by byte.
Prints the line and the character number where the two files diverge.
## Table of contents <!-- omit in toc -->
1. [TL;DR](#tldr)
1. [Further readings](#further-readings)
1. [Sources](#sources)
## TL;DR
```sh
# Print only lines present in both file1 and file2.
cmp 'path/to/file1' 'path/to/file2'
```
## Further readings
- [`comm`][comm]
- [man page]
## Sources
All the references in the [further readings] section, plus the following:
- [6 more terminal commands you should know]
<!--
references
-->
<!-- project -->
<!-- article sections -->
[further readings]: #further-readings
<!-- knowledge base -->
[comm]: comm.md
<!-- others -->
[6 more terminal commands you should know]: https://betterprogramming.pub/6-more-terminal-commands-you-should-know-3606cecdf8b6
[man page]: https://linux.die.net/man/1/cmp

View File

@@ -1,19 +1,60 @@
# comm
# `comm`
`comm` requires the files it is working with to be pre-sorted.
Compares two files line by line.
With no options, produces 3 columns in output:
- column 1 contains lines **unique to file 1**;
- column 2 contains lines **unique to file 2**;
- column 3 contains lines **common** to both files.
Comparisons honor the rules specified by 'LC_COLLATE'.
## Table of contents <!-- omit in toc -->
1. [TL;DR](#tldr)
1. [Further readings](#further-readings)
1. [Sources](#sources)
## TL;DR
```sh
# Print only lines present in both file1 and file2.
comm -12 'path/to/pre-sorted/file1' 'path/to/pre-sorted/file2'
# Print unique lines of file1 which are not present in file2.
comm -23 <(sort -u 'file1') <(sort -u 'file2')
comm -23 'path/to/pre-sorted/file1' 'path/to/pre-sorted/file2'
comm -23 <(sort -u 'path/to/file1') <(sort -u 'path/to/file2')
# Check the whole content of file1 is present in file2.
[[ $(comm -23 <(sort -u 'file1') <(sort -u 'file2') | wc -l) -eq 0 ]]
test $(comm -23 'path/to/pre-sorted/file1' <(sort -u 'path/to/file2') | wc -l) -eq 0
[[ $(comm -23 <(sort -u 'path/to/file1') 'path/to/pre-sorted/file2' | wc -l) -eq 0 ]]
```
## Further readings
- [`cmp`][cmp]
- [man page]
## Sources
- [Check whether all lines of file occur in different file]
All the references in the [further readings] section, plus the following:
- [Check whether all lines of file occur in different file]
- [6 more terminal commands you should know]
<!--
references
-->
<!-- project -->
<!-- article sections -->
[further readings]: #further-readings
<!-- knowledge base -->
[cmp]: cmp.md
<!-- others -->
[6 more terminal commands you should know]: https://betterprogramming.pub/6-more-terminal-commands-you-should-know-3606cecdf8b6
[check whether all lines of file occur in different file]: https://unix.stackexchange.com/questions/397747/check-whether-all-lines-of-file-occur-in-different-file#397749
[man page]: https://linux.die.net/man/1/comm

37
knowledge base/iptab.md Normal file
View File

@@ -0,0 +1,37 @@
# `iptab`
Displays a reference table of subnet masks and other IP address space details.
It has no arguments. That's it.
## Table of contents <!-- omit in toc -->
1. [TL;DR](#tldr)
1. [Further readings](#further-readings)
1. [Sources](#sources)
## TL;DR
```sh
iptab
```
## Further readings
## Sources
All the references in the [further readings] section, plus the following:
- [6 more terminal commands you should know]
<!--
references
-->
<!-- project -->
<!-- article sections -->
[further readings]: #further-readings
<!-- knowledge base -->
<!-- others -->
[6 more terminal commands you should know]: https://betterprogramming.pub/6-more-terminal-commands-you-should-know-3606cecdf8b6

56
knowledge base/jot.md Normal file
View File

@@ -0,0 +1,56 @@
# `jot`
Generates sequential or random data.
## Table of contents <!-- omit in toc -->
1. [TL;DR](#tldr)
1. [Further readings](#further-readings)
1. [Sources](#sources)
## TL;DR
```sh
# Print 21 evenly spaced increasing numbers from -1 to 1.
jot '21' '-1' '1.00'
jot -p '2' '21' '-1' '1'
# Print all ASCII characters.
jot -c '128' '0'
# Print all strings from 'xaa' to 'xaz'.
jot -w 'xa%c' '26' 'a'
# Print 20 random 8-letter strings.
jot -r -c '160' 'a' 'z' | rs -g '0' '8'
# Create files containing a bunch of 'x' characters for exactly 1024 bytes of
# data.
jot -b 'x' '512' > 'file.txt'
# Print all lines of 80 characters or longer.
grep $(jot -s "" -b '.' '80') 'file.txt'
```
## Further readings
- [`man` page][man page]
## Sources
All the references in the [further readings] section, plus the following:
- [6 more terminal commands you should know]
<!--
references
-->
<!-- project -->
<!-- article sections -->
[further readings]: #further-readings
<!-- knowledge base -->
<!-- others -->
[6 more terminal commands you should know]: https://betterprogramming.pub/6-more-terminal-commands-you-should-know-3606cecdf8b6
[man page]: https://manned.org/jot

View File

@@ -0,0 +1,3 @@
# Log (record) a terminal session
See [`script`](script.md).

56
knowledge base/script.md Normal file
View File

@@ -0,0 +1,56 @@
# `script`
Make a typescript file (a.k.a. log a.k.a. recording) of a terminal session.
## Table of contents <!-- omit in toc -->
1. [TL;DR](#tldr)
1. [Further readings](#further-readings)
1. [Sources](#sources)
## TL;DR
```sh
# Start recording.
# Defaults to a file named "typescript".
script
script 'file.log'
# Stop recording.
exit
# Append to an existing file.
script -a 'file.log'
# Execute quietly.
# Avoids 'start' and 'done' messages.
script -q 'file.log'
# Flush output after each write.
script -f
```
## Further readings
- [6 more terminal commands you should know]
- [`man`][man]
## Sources
All the references in the [further readings] section, plus the following:
- [cheat.sh]
<!--
references
-->
<!-- project -->
<!-- article sections -->
[further readings]: #further-readings
<!-- knowledge base -->
<!-- others -->
[6 more terminal commands you should know]: https://betterprogramming.pub/6-more-terminal-commands-you-should-know-3606cecdf8b6
[cheat.sh]: https://cheat.sh/script
[man]: https://manned.org/script

View File

@@ -55,6 +55,9 @@ ssh-add -L
ssh-copy-id 'host.fqdn'
ssh-copy-id -i "${HOME}/.ssh/id_rsa.pub" 'user@host.fqdn'
# Preload trusted keys.
ssh-keyscan 'host.fqdn' >> "${HOME}/.ssh/known_hosts"
# Connect to an unreachable host tunnelling the session through a bastion.
ssh -t 'bastion-host' ssh 'unreachable-host'