Renaming files in S3

+3 votes

I wish to rename all the files in csv format. Can do that S3.

Apr 5, 2018 in AWS by brat_1
• 7,200 points

recategorized Oct 16, 2018 by Priyaj 31,308 views

6 answers to this question.

+2 votes

Yes you can rename files in bulk. To do this you may need AWS Command Line Interface (CLI). A simple script may just about serve your purpose. Follow these steps:

  1. start by Installing and launch the AWS Command Line Interface (CLI).
  2. Log in to it.
  3. try the following script::
    aws s3 –recursive mv s3://<bucketname>/<folder_name_from>/<old_file_name> s3://<bucket>/<folder_name_to>/<new_file_name>
  4. Pass in foolowing information: that is the bucket name, folder name and new file name.
  5. You should be good to go.

You may also try file renaming softwares. there are quite in the market. There is one called as 'File Renamer'

answered Apr 5, 2018 by hemant
• 5,790 points
+2 votes

There is no direct method to rename the file in s3. what do you have to do is copy the existing file with new name (Just set the target key) and delete the old one.

answered Oct 16, 2018 by papa_jones
+2 votes

Used this and it worked pretty well

aws s3 --recursive mv s3://<bucketname>/<folder_name_from> s3://<bucket>/<folder_name_to>
answered Oct 16, 2018 by patrick dallas
+2 votes

Try using this, as i suppose you want to rename all the files to some other name, hope this helps.

aws s3 cp s3://source_folder/ s3://destination_folder/ --recursive
aws s3 rm s3://source_folder --recursive

Hope this helps!

Check out AWS DevOps Course here to learn more.

Thanks!

answered Oct 16, 2018 by raju singh

edited Jul 10, 2023 by Khan Sarfaraz
+2 votes

You can either use AWS CLI or s3cmd command to rename the files and folders in AWS S3 bucket.

Using S3cmd, use the following syntax to rename a folder,

s3cmd --recursive mv s3://<s3_bucketname>/<old_foldername>/ s3://<s3_bucketname>/<new_folder_name>

Using AWS CLI, use the following syntax to rename a folder,

aws s3 --recursive mv s3://<s3_bucketname>/<old_foldername>/ s3://<s3_bucketname>/<new_folder_name>
answered Oct 16, 2018 by petter dj
+1 vote
Try this python code. i am using it for renaming single csv file, but you can easily change it

try:
    client = boto3.client('s3')
    ## Get a list of files with prefix (we know there will be only one file)
    response = client.list_objects(
        Bucket = dpm_share_bucket,
        Prefix = srcPrefix
    )
    name = response["Contents"][0]["Key"]
    
    ## Store Target File File Prefix, this is the new name of the file
    target_source = {'Bucket': dpm_share_bucket, 'Key': name}
    target_key = PREFIX + 'column_mappings.csv'
    
    ### Now Copy the file with New Name
    client.copy(CopySource=target_source, Bucket=BUCKET_NAME, Key=target_key)
    
    ### Delete the old file
    client.delete_object(Bucket=dpm_share_bucket, Key=name)
except Exception as e:
        ## do nothing
        print('error occured')
answered Feb 26, 2020 by Sirish Saxena

Related Questions In AWS

0 votes
2 answers

How to access files in S3 bucket from R?

You can take a look at the ...READ MORE

answered Aug 10, 2018 in AWS by Deepthi
• 300 points
6,633 views
0 votes
1 answer

How do you concatenate small sized files in Amazon S3?

Amazon S3 does not provide a concatenate ...READ MORE

answered Sep 3, 2018 in AWS by Archana
• 4,170 points
5,375 views
0 votes
1 answer

Copying existing files in a s3 Bucket to another s3 bucket

Suppose the two buckets in question are ...READ MORE

answered Sep 14, 2018 in AWS by Priyaj
• 58,020 points
15,016 views
0 votes
1 answer

How to make multiple files in Amazon S3 public?

I had to change several hundred thousand ...READ MORE

answered Oct 17, 2018 in AWS by Archana
• 4,170 points
1,094 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,063 views
+1 vote
2 answers

AWS CloudWatch Logs in Docker

The awslogs works without using ECS. you need to configure ...READ MORE

answered Sep 7, 2018 in AWS by bug_seeker
• 15,510 points
2,069 views
+1 vote
2 answers
0 votes
3 answers

What is CPU Credit Balance in EC2 for AWS?

When you use fewer CPU resources then ...READ MORE

answered Nov 30, 2018 in AWS by Aniket
2,505 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP