Looking to download files or whole buckets from S3 Bucket on your local machine with AWS CLI on Linux Mint?

If so, I'll show you all the steps in order to install AWS CLI, list files and download them.

You might be interested also in:

Step 1: Install AWS CLI on Linux Mint

To start let's install the AWS S3 CLI on Linux Mint. This can be done by:

  • for a virtual Python environment - preferred way for me
pip install awscli
  • on your system by:
sudo pip install awscli

Another option for installation is by downloading the package. For more information please check: Install the AWS CLI version 2 on Linux

Step 2: Configure AWS S3 CLI client - add credentials

Next step is to configure your client in order to add AWS Access and Secret keys.. This is done by command:

aws configure

You will be asked for the following information:

AWS Secret Access Key [None]: tr7MtGbCEXAMPLEUtk/h3yCo8nvbEXAMPLEKEY
Default region name [None]: eu-central-1
Default output format [None]: json

The two important fields are:

  • AWS Access Key ID
  • AWS Secret Access Key

Both should be valid in order to access and download information from S3 bucket.

Step 3: List files and folders with AWS S3 CLI client

Before downloading files or folders you may want to list the files and check information about the files. This can be done by command:

aws s3 ls

if you need more details you can add parameters:

aws s3 ls -a

If you need to list information from specific bucket and folders you can use next syntax:

aws s3 ls s3://mybucket/data/files/

Step 4: Download single file from S3 bucket

If you like to download a single file on your machine with AWS S3 CLI client then you need to use the command - cp.

In the example below were are downloading myimage.jpg file (from bucket s3://mybucket and folder data/files/ ) to our local machine:

aws s3 cp s3://mybucket/data/files/myimage.jpg localfile.jpg

You need to provide a file name - how to be named the file locally on your machine or folder where to be downloaded. If you like to download the file in your Download folder you can use:

aws s3 cp s3://mybucket/data/files/myimage.jpg ~/Downloads/

Step 5: Download whole S3 bucket with AWS S3 CLI

Finally let's check how to download the whole bucket with AWS CLI. Again we need to use the command - cp with slightly different format.

If you need to download bucket - s3://mybucket and folder data/files/ you can use command:

aws s3 cp s3://mybucket/data/files/myimage.jpg ~/Downloads/ --recursive

this is going to download all files and folders(with nested ones) to your local machine - folder - Downloads.

Next examples will help you to download whole bucket vs folder from a bucket:

aws s3 cp s3://Bucket LocalFolder --recursive
aws s3 cp s3://Bucket/Folder/AnotherFolder LocalFolder --recursive

Note: command sync can be used in order to synchronize S3 folder and local one:

aws s3 sync s3://Bucket LocalFolder