This is an old revision of the document!
Metadata Management via CLI
The iCommands
allow to execute most metadata tasks also via command-line interface (CLI). This section will explain how to:
- Read/List metadata
- Create metadata
- Modify metadata
- Set new metadata value
- Remove metadata
- Copy metadata
- Query metadata
While the iCommands Wiki section contains the information to get you started using the iCommands
and also lists the commands that can be used for metadata management, the current section will further built on top of this by providing more detailed examples.
Notes:
- If you want to work with metadata templates, you have to use the web portal for the creation and filling of the templates.
- Within the RDMS, metadata is always added as so called 'attribute-value-units' triples, AVUs. The 'attribute' specifies the metadata key (e.g. 'Author') while the 'value' specifies the corresponding value for this key (e.g. 'John Doe'). The 'unit' entry is optional, but can be useful in cases where the entries could be otherwise ambiguous (e.g. A: 'Distance', V: '100', U: 'km'). This can be left blank if no unit is desired.
- When working with the
imeta
command, you have to specify if you are working on a file (data object) or folder (collection). This can be achieved by specifying the additional-d
(for files) or-C
(for folders) flags when using the command (see below for examples). - For all of the
imeta
command, you can use single or double quotes around an entry if it includes blanks, for exampleimeta add -d <path> Author 'Name Surname
'.
iCommands for Metadata Management
The imeta
command is the relevant sub-command from the iCommands
packages that is used to work with metadata from the CLI.
You can execute the following command from the CLI to get an explanation of the imeta
command as well as an overview of its possible usage:
$ imeta help
Furthermore, you can execute imeta help <subcommand>
to get a more detailed help displayed for the respective subcommand of imeta
.
For example imeta help add
would display information about the imeta add
subcommand which can be used to add metadata from the CLI (see below for examples).
Read/List Metadata
Adding Metadata
Modifying Metadata
Set Metadata
Removing Metadata
Copy Metadata
To copy metadata to a file/folder from another, the following commands is used:
$ imeta cp [-d, -C] <path_soruce> <path_dest>
where <path_source>
specifies the relative or absolute path to the data from which the metadata should be copied, and<path_source>
specifies the relative or absolute path to the data to which the metadata should be copied.
Note:
This functionality is currently blocked on our system!
Query Metadata
Using the Interactive Mode
It is also possible to use the imeta
command in an interactive mode. To enter the interactive mode, just type imeta
without any additional subcommand.
You can see that you are in the interactive mode of imeta
when the imeta>
is displayed in your terminal.
Once in the interactive mode, subsequent commands can be added after each other. If you want to leave the interactive mode again, type q
or quit
and confirm.
Examples:
# First check that the metadata that is currently set for the example file. $ imeta ls -d example_file_5 AVUs defined for dataObj /rug/home/rdms-testers@rug.nl/example_file_5: None # Enter the interactive mod and subsequently execute different imeta tasks before exiting the interactive mode. $imeta imeta>add -d example_file_5 Type 'Test File' imeta>add -d example_file_5 Author "John Doe" imeta>add -d example_file_5 Distance 10e-5 km imeta>quit # Check again to see if all tasks were executed. $ $ imeta ls -d example_file_5 AVUs defined for dataObj /rug/home/rdms-testers@rug.nl/example_file_5: attribute: Author value: John Doe units: ---- attribute: Distance value: 10e-5 units: km ---- attribute: Type value: Test File units:
Further Tips
This section contains some further important and helpful tips for the working with metadata from the CLI.
Copying Files and Metadata
When copying a folder/file that contains metadata, the metadata is not copied to the copy of the file/folder!
# Check metadata for the original $ imeta ls -d example_file_9 AVUs defined for dataObj /rug/home/rdms-testers@rug.nl/example_file_9: attribute: Author value: Tester_2 units: ---- attribute: Distance value: 150 units: km # Make a copy of the file. $ icp example_file_9 example_file_9_copy # Check metadata for the copy. $ imeta ls -d example_file_9_copy AVUs defined for dataObj /rug/home/rdms-testers@rug.nl/example_file_9_copy: None
Advanced Usages
Of course, as with other iCommands
, it is possible to include the imeta
sub-command in scripts etc. to execute more advanced/extended tasks.
The interactive imeta
mode can be also used to pipe information into it and then automatically execute the desired tasks.
For example, one could combine and iquest
query to first select files that fulfill the query condition and then use this information to set metadata on all those files with one terminal statement:
# This example will first query for all files in the collection at '<path>' that have a name of the type 'TEST%' (e.g. 'TEST_Sample', 'TEST_Reaction', etc.). # It will then use this query result and use them for the 'set -d <path>/<filename> <attribute> <value> <unit>' statement. # This will then be piped into 'imeta'. As a result the AVUs specified in the 'set' statement will be added to all files that met the query condition. iquest 'set -d %s/%s <attribute> <value> <unit>' "select COLL_NAME, DATA_NAME where COLL_NAME = '<path>' and DATA_NAME like 'TEST%'" | imeta