azureazure-blob-storageazure-cli

How to get a list of files in an Azure blob storage with "az" command line tool?


So far I have been using az storage blob directory list -c <ContainerName> -d <DirectoryName> and it has been working. It returns a JSON list of files. Not ideal but it works.

The output contains a warning that the command above is deprecated:

This command is implicitly deprecated because command group 'storage blob directory' is deprecated and will be removed in a future release. Use 'az storage fs directory' instead.

I tried several different ways to use it but it just does not work. az storage fs directory list -f <ContainerName> --path <DirectoryName> --recursive returns an empty list. az storage fs directory exists -f <ContainerName> -n <DirectoryName> returns false. So... I have no idea what to switch to to get a list of my files in Azure.

What is the correct new way to get the list of files in a blob?


Solution

  • How to get a list of files in an Azure blob storage with "az" command line tool?

    Since the az storage blob directory command group is deprecated, you can use the az storage blob list command instead.

    Command:

    az storage blob list --container-name <ContainerName> --prefix <DirectoryName>/ --account-name <StorageAccount> 
    

    Output: enter image description here

    The above command will list all blobs that have <DirectoryName>/ as a prefix.

    Reference: az storage blob | Microsoft Learn