The aws s3 ls command is a part of the AWS Command Line Interface (CLI) and is used to list AWS S3 buckets, folders (prefixes), and files (objects). It provides a convenient way to retrieve information about the contents of your S3 storage.
Here’s an overview of the aws s3 ls command and its functionality:
- Listing S3 Buckets: When executed without any additional arguments, the aws s3 ls command returns a list of all your S3 buckets. This includes the names and creation dates of the buckets.
- Listing Objects in a Bucket: By specifying the bucket name as an argument, the aws s3 ls command can list the objects (files) stored within a specific S3 bucket. It provides information such as the object name, size, and last modified timestamp.
- Listing Objects with Prefixes/Folders: The aws s3 ls command can list objects within a specific “prefix” or folder in an S3 bucket. By specifying the bucket name and a prefix, you can retrieve a list of objects within that particular folder or prefix.
- Recursive Listing: The aws s3 ls command provides an option (–recursive) to perform a recursive listing of objects. This allows you to retrieve a complete listing of all objects within a bucket or a specific prefix, including objects within subfolders.
- Output Formats: The aws s3 ls command supports different output formats, such as table, JSON, or CSV. You can choose the format that best suits your needs and use it to process or further analyze the listing information.
The aws s3 ls command is particularly useful when you need to explore the contents of your S3 storage, identify specific objects or folders, or perform automated operations based on the listing results.
aws s3 ls Command Examples
1. List all buckets:
# aws s3 ls
2. List files and folders in the root of a bucket (s3:// is optional):
# aws s3 ls s3://bucket_name
3. List files and folders directly inside a directory:
# aws s3 ls bucket_name/path/to/directory/
4. List all files in a bucket:
# aws s3 ls --recursive bucket_name
5. List all files in a path with a given prefix:
# aws s3 ls --recursive bucket_name/path/to/directory/ prefix
6. Display help:
# aws s3 ls help