Sort and Filter

Several of the Files.com API resources have list operations that return multiple instances of the resource. The List operations can be sorted and filtered.

Sorting

To sort the returned data, use the --sort-by parameter.

Sort Syntax

--sort-by="field=asc"

Valid directions are asc and desc.

Special note about the List Folder Endpoint

For historical reasons, and to maintain compatibility with a variety of other cloud-based MFT and EFSS services, Folders will always be listed before Files when listing a Folder. This applies regardless of the sorting parameters you provide. These will be used, after the initial sort application of Folders before Files.

Sort Example

files-cli users list \
  --sort-by="username=asc"

Filtering

Filters apply selection criteria to the underlying query that returns the results. They can be applied individually or combined with other filters, and the resulting data can be sorted by a single field.

Each resource supports a unique set of valid filter fields, filter combinations, and combinations of filters and sort fields.

FlagTypeDescription
--filter="field=value"ExactFind resources that have an exact field value match to a passed in value. (i.e., FIELD_VALUE = PASS_IN_VALUE).
--filter-prefix="field=value"PatternFind resources where the specified field is prefixed by the supplied value. This is applicable to values that are strings.
--filter-gt="field=value"RangeFind resources that have a field value that is greater than the passed in value. (i.e., FIELD_VALUE > PASS_IN_VALUE).
--filter-gteq="field=value"RangeFind resources that have a field value that is greater than or equal to the passed in value. (i.e., FIELD_VALUE >= PASS_IN_VALUE).
--filter-lt="field=value"RangeFind resources that have a field value that is less than the passed in value. (i.e., FIELD_VALUE < PASS_IN_VALUE).
--filter-lteq="field=value"RangeFind resources that have a field value that is less than or equal to the passed in value. (i.e., FIELD_VALUE <= PASS_IN_VALUE).

Use --filter-by for client-side wildcard filtering after records are fetched.

--filter-by="field_name=*.jpg"

Exact Filter Example

files-cli users list \
  --filter="not_site_admin=true"

Pattern Filter Example

files-cli users list \
  --filter-prefix="username=test"

Range Filter Example

files-cli action-logs list \
  --filter-gteq="created_at=2024-01-01"

Combination Filter with Sort Example

files-cli users list \
  --filter="not_site_admin=true" \
  --filter-prefix="username=test" \
  --sort-by="username=asc"

Client-side Filter Example

files-cli folders ls some/path \
  --filter-by="path=*.jpg"