695 And of course, we can generate multiple relations from a single XML using a single XQuery script. |
695 And of course, we can generate multiple relations from a single XML using a single XQuery script. |
696 XQuery can be also used for operations like JOIN or UNION and for filtering and other transformations |
696 XQuery can be also used for operations like JOIN or UNION and for filtering and other transformations |
697 as will be shown in further examples. |
697 as will be shown in further examples. |
698 </p> |
698 </p> |
699 |
699 |
|
700 <h2>Read files metadata using relpipe-in-filesystem</h2> |
|
701 |
|
702 <p> |
|
703 Our filesystems contain valuable information and using proper tools we can extract them. |
|
704 Using <code>relpipe-in-filesystem</code> we can gather metadata of our files and process them in relational way. |
|
705 This tools does not traverse our filesystem (remember the rule: <em>do one thing and do it well</em>), |
|
706 instead, it eats list of file paths separated from standard input. |
|
707 It is typically used together with the <code>find</code> command, but we can also create such list by hand using e.g. <code>printf</code> command. |
|
708 </p> |
|
709 |
|
710 <m:pre jazyk="bash">find /etc/ssh/ -print0 | relpipe-in-filesystem | relpipe-out-tabular</m:pre> |
|
711 |
|
712 <p> |
|
713 In the basic scenario, it behaves like <code>ls -l</code>, just more modular and machine-readable: |
|
714 </p> |
|
715 |
|
716 <pre><![CDATA[filesystem: |
|
717 ╭───────────────────────────────────┬───────────────┬────────────────┬────────────────┬────────────────╮ |
|
718 │ path (string) │ type (string) │ size (integer) │ owner (string) │ group (string) │ |
|
719 ├───────────────────────────────────┼───────────────┼────────────────┼────────────────┼────────────────┤ |
|
720 │ /etc/ssh/ │ d │ 0 │ root │ root │ |
|
721 │ /etc/ssh/moduli │ f │ 553122 │ root │ root │ |
|
722 │ /etc/ssh/ssh_host_ecdsa_key │ f │ 227 │ root │ root │ |
|
723 │ /etc/ssh/sshd_config │ f │ 3262 │ root │ root │ |
|
724 │ /etc/ssh/ssh_host_ed25519_key.pub │ f │ 91 │ root │ root │ |
|
725 │ /etc/ssh/ssh_host_ecdsa_key.pub │ f │ 171 │ root │ root │ |
|
726 │ /etc/ssh/ssh_host_rsa_key │ f │ 1679 │ root │ root │ |
|
727 │ /etc/ssh/ssh_config │ f │ 1580 │ root │ root │ |
|
728 │ /etc/ssh/ssh_host_ed25519_key │ f │ 399 │ root │ root │ |
|
729 │ /etc/ssh/ssh_import_id │ f │ 338 │ root │ root │ |
|
730 │ /etc/ssh/ssh_host_rsa_key.pub │ f │ 391 │ root │ root │ |
|
731 ╰───────────────────────────────────┴───────────────┴────────────────┴────────────────┴────────────────╯ |
|
732 Record count: 11]]></pre> |
|
733 |
|
734 <p> |
|
735 We can specify desired attributes and also their aliases: |
|
736 </p> |
|
737 |
|
738 <m:pre jazyk="bash"><![CDATA[find /etc/ssh/ -print0 \ |
|
739 | relpipe-in-filesystem \ |
|
740 --file path --as artefact \ |
|
741 --file size \ |
|
742 --file owner --as dear_owner \ |
|
743 | relpipe-out-tabular]]></m:pre> |
|
744 |
|
745 <p>And we will get a subset with renamed attributes:</p> |
|
746 |
|
747 <pre><![CDATA[filesystem: |
|
748 ╭───────────────────────────────────┬────────────────┬─────────────────────╮ |
|
749 │ artefact (string) │ size (integer) │ dear_owner (string) │ |
|
750 ├───────────────────────────────────┼────────────────┼─────────────────────┤ |
|
751 │ /etc/ssh/ │ 0 │ root │ |
|
752 │ /etc/ssh/moduli │ 553122 │ root │ |
|
753 │ /etc/ssh/ssh_host_ecdsa_key │ 227 │ root │ |
|
754 │ /etc/ssh/sshd_config │ 3262 │ root │ |
|
755 │ /etc/ssh/ssh_host_ed25519_key.pub │ 91 │ root │ |
|
756 │ /etc/ssh/ssh_host_ecdsa_key.pub │ 171 │ root │ |
|
757 │ /etc/ssh/ssh_host_rsa_key │ 1679 │ root │ |
|
758 │ /etc/ssh/ssh_config │ 1580 │ root │ |
|
759 │ /etc/ssh/ssh_host_ed25519_key │ 399 │ root │ |
|
760 │ /etc/ssh/ssh_import_id │ 338 │ root │ |
|
761 │ /etc/ssh/ssh_host_rsa_key.pub │ 391 │ root │ |
|
762 ╰───────────────────────────────────┴────────────────┴─────────────────────╯ |
|
763 Record count: 11]]></pre> |
|
764 |
|
765 <p> |
|
766 We can also choose, which path format fits our needs best: |
|
767 </p> |
|
768 |
|
769 |
|
770 <m:pre jazyk="bash"><![CDATA[find ../../etc/ssh/ -print0 \ |
|
771 | relpipe-in-filesystem \ |
|
772 --file path \ |
|
773 --file path_absolute \ |
|
774 --file path_canonical \ |
|
775 --file name \ |
|
776 | relpipe-out-tabular]]></m:pre> |
|
777 |
|
778 <p>The <code>path</code> attribute contains the exact same value as was on input. Other formats are derived:</p> |
|
779 |
|
780 <pre><![CDATA[filesystem: |
|
781 ╭────────────────────────────────────────┬───────────────────────────────────────────────────┬───────────────────────────────────┬──────────────────────────╮ |
|
782 │ path (string) │ path_absolute (string) │ path_canonical (string) │ name (string) │ |
|
783 ├────────────────────────────────────────┼───────────────────────────────────────────────────┼───────────────────────────────────┼──────────────────────────┤ |
|
784 │ ../../etc/ssh/ │ /home/hack/../../etc/ssh/ │ /etc/ssh │ │ |
|
785 │ ../../etc/ssh/moduli │ /home/hack/../../etc/ssh/moduli │ /etc/ssh/moduli │ moduli │ |
|
786 │ ../../etc/ssh/ssh_host_ecdsa_key │ /home/hack/../../etc/ssh/ssh_host_ecdsa_key │ /etc/ssh/ssh_host_ecdsa_key │ ssh_host_ecdsa_key │ |
|
787 │ ../../etc/ssh/sshd_config │ /home/hack/../../etc/ssh/sshd_config │ /etc/ssh/sshd_config │ sshd_config │ |
|
788 │ ../../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 │ |
|
789 │ ../../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 │ |
|
790 │ ../../etc/ssh/ssh_host_rsa_key │ /home/hack/../../etc/ssh/ssh_host_rsa_key │ /etc/ssh/ssh_host_rsa_key │ ssh_host_rsa_key │ |
|
791 │ ../../etc/ssh/ssh_config │ /home/hack/../../etc/ssh/ssh_config │ /etc/ssh/ssh_config │ ssh_config │ |
|
792 │ ../../etc/ssh/ssh_host_ed25519_key │ /home/hack/../../etc/ssh/ssh_host_ed25519_key │ /etc/ssh/ssh_host_ed25519_key │ ssh_host_ed25519_key │ |
|
793 │ ../../etc/ssh/ssh_import_id │ /home/hack/../../etc/ssh/ssh_import_id │ /etc/ssh/ssh_import_id │ ssh_import_id │ |
|
794 │ ../../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 │ |
|
795 ╰────────────────────────────────────────┴───────────────────────────────────────────────────┴───────────────────────────────────┴──────────────────────────╯ |
|
796 Record count: 11]]></pre> |
|
797 |
|
798 <p> |
|
799 We can also <em>select</em> symlink targets or their types. |
|
800 If some file is missing or is inaccessible due to permissions, only <code>path</code> is printed for it. |
|
801 </p> |
|
802 |
|
803 <p> |
|
804 Tip: if we are looking for files in the current directory and want omit the „.“ we just call: <code>find -printf '%P\0'</code> instead of <code>find -print0</code>. |
|
805 </p> |
|
806 |
700 |
807 |
701 </text> |
808 </text> |
702 |
809 |
703 </stránka> |
810 </stránka> |