The `s3 cp` command is a powerful tool for managing files and directories in Amazon S3 buckets using the AWS Command Line Interface (CLI). It allows you to copy files between your local machine and S3 buckets, as well as between two S3 buckets. Here, we'll explore the basics of the `s3 cp` command with detailed examples.

Before diving into the examples, ensure you have configured your AWS CLI with the necessary access keys and region. You can do this by running `aws configure` and following the prompts.

Basic Syntax and Usage
The basic syntax of the `s3 cp` command is as follows:

s3 cp [options]
Here, source can be a local file path, an S3 bucket path, or even another S3 bucket, while destination can be an S3 bucket path or another local file path.

Copying Local Files to S3
To copy a local file to an S3 bucket, use the following command:
s3 cp local-file.txt s3://my-bucket/

This command will upload the local file `local-file.txt` to the `my-bucket` bucket in the root directory.
Copying S3 Objects to Local
To download an S3 object to your local machine, use the following command:

s3 cp s3://my-bucket/remote-file.txt .
This command will download the `remote-file.txt` object from the `my-bucket` bucket to the current directory.




















Working with Directories
The `s3 cp` command can also work with directories, recursively copying all files and subdirectories.
Copying Local Directories to S3
To upload a local directory to an S3 bucket, use the following command:
s3 cp local-directory/ s3://my-bucket/
This command will recursively upload all files and subdirectories in the `local-directory` to the `my-bucket` bucket.
Copying S3 Directories to Local
To download an S3 directory to your local machine, use the following command:
s3 cp s3://my-bucket/remote-directory/ .
This command will recursively download all files and subdirectories in the `remote-directory` from the `my-bucket` bucket to the current directory.
Copying Between S3 Buckets
You can also use the `s3 cp` command to copy objects between two S3 buckets.
Copying Objects from One S3 Bucket to Another
To copy an object from one S3 bucket to another, use the following command:
s3 cp s3://source-bucket/remote-file.txt s3://destination-bucket/
This command will copy the `remote-file.txt` object from the `source-bucket` bucket to the `destination-bucket` bucket.
Copying Directories Between S3 Buckets
To copy a directory from one S3 bucket to another, use the following command:
s3 cp s3://source-bucket/remote-directory/ s3://destination-bucket/
This command will recursively copy all files and subdirectories in the `remote-directory` from the `source-bucket` bucket to the `destination-bucket` bucket.
With these examples, you should now be well-equipped to use the `s3 cp` command for various file and directory management tasks in Amazon S3. Happy coding!