Our filesystems contain valuable information and using proper tools we can extract them.
Using relpipe-in-filesystem
we can gather metadata of our files and process them in relational way.
This tools does not traverse our filesystem (remember the rule: do one thing and do it well),
instead, it eats a list of file paths separated by \0
.
It is typically used together with the find
command, but we can also create such list by hand using e.g. printf
command or tr \\n \\0
.
find /etc/ssh/ -print0 | relpipe-in-filesystem | relpipe-out-tabular
In the basic scenario, it behaves like ls -l
, just more modular and machine-readable:
filesystem: ╭───────────────────────────────────┬───────────────┬────────────────┬────────────────┬────────────────╮ │ path (string) │ type (string) │ size (integer) │ owner (string) │ group (string) │ ├───────────────────────────────────┼───────────────┼────────────────┼────────────────┼────────────────┤ │ /etc/ssh/ │ d │ 0 │ root │ root │ │ /etc/ssh/moduli │ f │ 553122 │ root │ root │ │ /etc/ssh/ssh_host_ecdsa_key │ f │ 227 │ root │ root │ │ /etc/ssh/sshd_config │ f │ 3262 │ root │ root │ │ /etc/ssh/ssh_host_ed25519_key.pub │ f │ 91 │ root │ root │ │ /etc/ssh/ssh_host_ecdsa_key.pub │ f │ 171 │ root │ root │ │ /etc/ssh/ssh_host_rsa_key │ f │ 1679 │ root │ root │ │ /etc/ssh/ssh_config │ f │ 1580 │ root │ root │ │ /etc/ssh/ssh_host_ed25519_key │ f │ 399 │ root │ root │ │ /etc/ssh/ssh_import_id │ f │ 338 │ root │ root │ │ /etc/ssh/ssh_host_rsa_key.pub │ f │ 391 │ root │ root │ ╰───────────────────────────────────┴───────────────┴────────────────┴────────────────┴────────────────╯ Record count: 11
We can specify desired attributes and also their aliases:
find /etc/ssh/ -print0 \
| relpipe-in-filesystem \
--file path --as artefact \
--file size \
--file owner --as dear_owner \
| relpipe-out-tabular
And we will get a subset with renamed attributes:
filesystem: ╭───────────────────────────────────┬────────────────┬─────────────────────╮ │ artefact (string) │ size (integer) │ dear_owner (string) │ ├───────────────────────────────────┼────────────────┼─────────────────────┤ │ /etc/ssh/ │ 0 │ root │ │ /etc/ssh/moduli │ 553122 │ root │ │ /etc/ssh/ssh_host_ecdsa_key │ 227 │ root │ │ /etc/ssh/sshd_config │ 3262 │ root │ │ /etc/ssh/ssh_host_ed25519_key.pub │ 91 │ root │ │ /etc/ssh/ssh_host_ecdsa_key.pub │ 171 │ root │ │ /etc/ssh/ssh_host_rsa_key │ 1679 │ root │ │ /etc/ssh/ssh_config │ 1580 │ root │ │ /etc/ssh/ssh_host_ed25519_key │ 399 │ root │ │ /etc/ssh/ssh_import_id │ 338 │ root │ │ /etc/ssh/ssh_host_rsa_key.pub │ 391 │ root │ ╰───────────────────────────────────┴────────────────┴─────────────────────╯ Record count: 11
We can also choose, which path format fits our needs best:
find ../../etc/ssh/ -print0 \
| relpipe-in-filesystem \
--file path \
--file path_absolute \
--file path_canonical \
--file name \
| relpipe-out-tabular
The path
attribute contains the exact same value as was on input. Other formats are derived:
filesystem: ╭────────────────────────────────────────┬───────────────────────────────────────────────────┬───────────────────────────────────┬──────────────────────────╮ │ path (string) │ path_absolute (string) │ path_canonical (string) │ name (string) │ ├────────────────────────────────────────┼───────────────────────────────────────────────────┼───────────────────────────────────┼──────────────────────────┤ │ ../../etc/ssh/ │ /home/hack/../../etc/ssh/ │ /etc/ssh │ │ │ ../../etc/ssh/moduli │ /home/hack/../../etc/ssh/moduli │ /etc/ssh/moduli │ moduli │ │ ../../etc/ssh/ssh_host_ecdsa_key │ /home/hack/../../etc/ssh/ssh_host_ecdsa_key │ /etc/ssh/ssh_host_ecdsa_key │ ssh_host_ecdsa_key │ │ ../../etc/ssh/sshd_config │ /home/hack/../../etc/ssh/sshd_config │ /etc/ssh/sshd_config │ sshd_config │ │ ../../etc/ssh/ssh_host_ed25519_key.pub │ /home/hack/../../etc/ssh/ssh_host_ed25519_key.pub │ /etc/ssh/ssh_host_ed25519_key.pub │ ssh_host_ed25519_key.pub │ │ ../../etc/ssh/ssh_host_ecdsa_key.pub │ /home/hack/../../etc/ssh/ssh_host_ecdsa_key.pub │ /etc/ssh/ssh_host_ecdsa_key.pub │ ssh_host_ecdsa_key.pub │ │ ../../etc/ssh/ssh_host_rsa_key │ /home/hack/../../etc/ssh/ssh_host_rsa_key │ /etc/ssh/ssh_host_rsa_key │ ssh_host_rsa_key │ │ ../../etc/ssh/ssh_config │ /home/hack/../../etc/ssh/ssh_config │ /etc/ssh/ssh_config │ ssh_config │ │ ../../etc/ssh/ssh_host_ed25519_key │ /home/hack/../../etc/ssh/ssh_host_ed25519_key │ /etc/ssh/ssh_host_ed25519_key │ ssh_host_ed25519_key │ │ ../../etc/ssh/ssh_import_id │ /home/hack/../../etc/ssh/ssh_import_id │ /etc/ssh/ssh_import_id │ ssh_import_id │ │ ../../etc/ssh/ssh_host_rsa_key.pub │ /home/hack/../../etc/ssh/ssh_host_rsa_key.pub │ /etc/ssh/ssh_host_rsa_key.pub │ ssh_host_rsa_key.pub │ ╰────────────────────────────────────────┴───────────────────────────────────────────────────┴───────────────────────────────────┴──────────────────────────╯ Record count: 11
We can also select symlink targets or their types.
If some file is missing or is inaccessible due to permissions, only path
is printed for it.
Tip: if we are looking for files in the current directory and want omit the „.“ we just call: find -printf '%P\0'
instead of find -print0
.
Relational pipes, open standard and free software © 2018-2022 GlobalCode