How to alter permissions of all files or files with a specific extension via s3 command line client tool (Linux)?
S3 command line tool (S3 cmd) allows us to alter permissions of files and files with specific extensions inside S3 bucket recursively. Below are the steps that we have to follow to achieve it.
Step.1 Download this tool using wget command:
# wget https://excellmedia.dl.sourceforge.net/project/s3tools/s3cmd/2.0.0/s3cmd-2.0.0.zip
Step.2 Unzip the downloaded file:
# unzip s3cmd-2.0.0.zip
Step.3 Change directory to extracted one:
# cd s3cmd-2.0.0.0
Step.4 Now execute the installer using below command:
# python setup.py install
Note: If the system prompts to install python, then install accordingly.
Step.5 S3 Settings:
Execute below command and configure s3 settings.
# s3cmd –configure
Provide the s3 credentials which were generated using AWS – IAM.
For example:
AWS Access Key ID [None]: AKIAI44NAVNWBESAMPLE
AWS Secret Access Key [None]: e7NtGbCleBF3aVN8nwbEXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: text
Step.5 Change permissions of the whole bucket recursively or files with a specific extension:
1. Change permissions of the whole bucket recursively:
#!/bin/bash if [ "$USER" = root ]; then echo "This script shouldn't be run as root. Aborting." exit 1 Else s3cmd setacl s3://democontent/ --acl-public --recursive fi
Save it as .sh extension and run it to test
In the above script:
- a) s3://democontent/ : Bucket name
- b) –recursive : use recursive option to change permissions of the files recursively.
2. Change permissions for Specific file types only:
if [ "$USER" = root ]; then echo "This script shouldn't be run as root. Aborting." exit 1 Else s3cmd setacl s3://democontent/ --acl-private --recursive --include '*.html|*.gif' --exclude '*.jpg |*.png' fi
Save it as .sh extension and run it to test.
In the above script:
- a) –include : To include some specific extension files. To separate multiple file names use pipe symbol(|).
- b) –exclude : To exclude some specific extension files. To separate multiple file names use pipe symbol(|).