Azure CLI Storage File Commands

This section covers commands for managing Azure File Share resources using the Azure CLI.

Overview

Azure Files offers fully managed cloud file shares that are accessible via the industry-standard Server Message Block (SMB) protocol, Network File System (NFS) protocol, and are mountable concurrently from all of your Windows, Linux, and macOS cloud or on-premises deployments.

File Share Commands

Creating a File Share

Use the az storage share create command to create a new file share within a storage account.

az storage share create --name MyFileShare --account-name MyStorageAccount --account-key

Alternatively, you can use a connection string:

az storage share create --name MyFileShare --connection-string ""

Listing File Shares

To list all file shares in a storage account, use the az storage share list command.

az storage share list --account-name MyStorageAccount --account-key

Showing File Share Details

Get detailed information about a specific file share using az storage share show.

az storage share show --name MyFileShare --account-name MyStorageAccount --account-key

Deleting a File Share

Remove a file share with the az storage share delete command.

az storage share delete --name MyFileShare --account-name MyStorageAccount --account-key

File and Directory Commands

The Azure CLI also provides commands to manage files and directories within an Azure File Share.

Uploading a File

Upload a local file to a file share using az storage file upload.

az storage file upload --share-name MyFileShare --account-name MyStorageAccount --account-key --source --path

Downloading a File

Download a file from a file share using az storage file download.

az storage file download --share-name MyFileShare --account-name MyStorageAccount --account-key --path --destination

Listing Files and Directories

List the contents of a directory within a file share using az storage file list.

az storage file list --share-name MyFileShare --account-name MyStorageAccount --account-key --path

Creating a Directory

Create a new directory within a file share using az storage directory create.

az storage directory create --share-name MyFileShare --account-name MyStorageAccount --account-key --path

Deleting a File or Directory

Delete a file or directory using az storage file delete or az storage directory delete.

# Delete a file az storage file delete --share-name MyFileShare --account-name MyStorageAccount --account-key --path # Delete a directory (non-empty directories require --recursive) az storage directory delete --share-name MyFileShare --account-name MyStorageAccount --account-key --path --recursive

Common Parameters

Parameter Description Required
--account-name The name of the storage account. Yes (unless using connection string)
--account-key The access key for the storage account. Yes (if not using SAS token or connection string)
--share-name The name of the file share. Yes (for file/directory operations)
--name The name of the file share (for share operations). Yes (for share operations)
--path The path within the file share for files and directories. No
--source Path to the local file to upload. Yes (for upload)
--destination Path to the local destination for download. Yes (for download)

Note: Replace placeholders like MyFileShare, MyStorageAccount, <your_account_key>, <your_connection_string>, and file paths with your actual values.

Tip: For easier management, consider using Azure Key Vault to store your storage account keys.

Warning: Deleting a directory recursively will permanently remove all its contents. Use with caution.