Leticia Esperon
Leticia Esperon

Reputation: 2851

Is there a way to add a time stamp in all file names in a folder?

I'm currently using aws cli in a linux EC2 instance to move files from a folder to an s3 bucket. I would like the files to be moved to have the current time or even better, the file created at date in their name. Is that possible? This is my command:

aws s3 mv /home/wowza/content/ s3://bucket/folder/ --recursive

It doesn't have to be an aws cli command. It can be commands that rename all the files in the folder and then I run the aws s3 command.

Upvotes: 1

Views: 2655

Answers (2)

Leticia Esperon
Leticia Esperon

Reputation: 2851

I learned that linux doesnt record creation time but I could add the current date to all my files like this:

for f in test/*; do mv -- "$f" "$f-$(stat -c %Y "$f" | date +%Y%m%d)"; done

Upvotes: 1

David Álvaro
David Álvaro

Reputation: 121

you could rename the files in #bash (using for) and then upload to AWS s3.

for f in test/*; do TIMESTAMP=$(date +%s); FILENAME=${f%.*}; EXTENSION=${f##*.}; NEWNAME="$FILENAME-$TIMESTAMP.$EXTENSION"; mv $f $NEWNAME; done

Upvotes: 1

Related Questions