Understanding Virtual Directories in AIStore: The —nr and —no-dirs Flags
Understanding Virtual Directories in AIStore: The —nr and —no-dirs Flags
Table of Contents
- What are Virtual Directories?
- Flag Definitions
- How These Flags Interact
- Flag Summary Table
- Examples
- Common Use Cases
- Recap
AIStore supports the concept of virtual directories, allowing for hierarchical organization of objects within buckets.
When listing objects via supported APIs (or CLI ais ls), two important flags control how these virtual directories are handled: --nr (non-recursive) and --no-dirs. Understanding the interaction between these flags is essential.
What are Virtual Directories?
In AIStore, virtual directories are indicated implicitly by using the slash (/) character in object names.
For example, an object named data/logs/file1.log implies virtual directories data/ and data/logs/.
Unlike traditional POSIX filesystems, the virtual directories are derived from the object names and provide a hierarchical view of your stored objects.
Flag Definitions
--nr (Non-Recursive)
- Purpose: Limits listing to only the immediate objects under the specified prefix
- Behavior: Prevents traversal into subdirectories but includes virtual directories
- Default: Off (recursive listing is the default behavior)
--no-dirs
- Purpose: Excludes virtual directories from the listing results
- Behavior: Filters out directory entries (object prefixes ending with
/) - Default: On (directories are hidden by default), unless
--nris specified
How These Flags Interact
The interaction between these flags can be confusing but follows a logical pattern:
- Default Behavior (no flags): Lists all objects recursively but hides virtual directories
- With
--nr: Shows only top-level entries (both objects and directories) without recursing - With
--no-dirs: Lists all objects recursively but hides virtual directory entries - With both
--nr --no-dirs: Shows only immediate objects (no directories, no recursion)
Flag Summary Table
Examples
Default Recursive Listing
The default behavior shows all objects recursively and hides virtual directories:
Using Unix-style path notation produces the same result:
A more complex example showing recursive listing with a specific prefix:
You can also use Unix-style directory notation, which is equivalent to the previous command:
Non-Recursive Listing
The --nr flag shows only top-level entries without recursing into subdirectories:
This is especially useful for exploring directory structure at a specific depth:
Filtering Directories
The --no-dirs flag is implied by default and can be explicitly specified to hide directory entries:
Similarly, with a more complex structure:
Combined Flags
When both --nr and --no-dirs flags are used together, only immediate objects are shown (no directories and no recursion):
In this case, no results appear because there are only directories at the top level. The --nr flag restricts listing to immediate objects, while --no-dirs excludes the virtual directories.
Exploring Complex Directory Structures
You can view both directories and objects at a specific level using --nr:
This shows both the current directory and immediate objects without recursing further.
Common Use Cases
- List top-level directories only:
- List all objects without directory entries:
Note: --no-dirs is implied by default
- Show all objects with full paths:
The --all flag shows both objects and directories at all levels
Recap
- The
--nrflag is particularly useful when exploring a bucket’s structure level by level - When using prefixes with
--nr, only the immediate level below the prefix is shown - If a prefix points directly to an object rather than a directory, using
--nrwon’t affect the output - When both flags are used together, you might see an empty result if there are no immediate objects at that level
- For large buckets with complex directory structures, using these flags wisely can significantly improve listing performance and readability