Table of contents
Some useful commands for Bucket on S3
-
To create a new bucket.
aws s3 --profile manhpd mb s3://<name-bucket>
In this case, we will use
mb
command to make a new bucket.mb
stands formake bucket
.For example:
aws s3 --profile manhpd mb s3://test-bucket
-
To remove a bucket.
aws s3 --profile manhpd rb s3://<name-bucket> --force
-
To list all buckets in S3.
aws s3 --profile manhpd ls
Then, we have:
Some useful commands for Files on S3
-
To copy a file in the local to a bucket in S3.
aws s3 --profile manhpd cp local-file s3://<name-bucket>
For example:
# create a new text file echo "This is file 2" >> sample2.txt # Copy this file to S3 bucket aws s3 --profile manhpd cp sample2.txt s3://test-bucket
For example:
At the same time, checking on S3 bucket -
s3manhpd
, we have: -
To move a local file to a bucket in S3.
aws s3 --profile manhpd mv local-file s3://<name-bucket>
-
To move file from S3 to the local
aws s3 --profile manhpd mv s3://name-bucket/name-file ./
-
To move a file in S3 bucket.
aws s3 --profile manhpd mv s3://name-bucket/name-file
-
To remove a file in S3 bucket.
aws s3 --profile manhpd rm s3://name-bucket/name-file
-
To rename a file in S3.
aws s3 --profile manhpd cp file-path s3://name-bucket/different-name-file
-
List all files in a bucket.
aws s3 --profile manhpd ls s3://name-bucket --recursive --human-readable --summarize
-
List all files in a folder of a bucket.
aws s3 --profile manhpd ls s3://name-bucket/name-folder --recursive --human-readable --summarize
For example:
-
List only the filenames of a S3 bucket.
aws s3api --profile manhpd list-objects --bucket <name-bucket> --output text --query "Contents[].{Key: Key}"