I have downloaded multiple files from different s3 buckets to a single folder on a linux vm. I want to rename only the *.gz
files in the directory, preferably sequentially, using a script to something like FILE001_$(date ' %Y%m%d').csv.gz
,FILE002_$(date ' %Y%m%d').csv.gz
etc, before moving them to client's sftp server(existing process).
I tried using find . -name "*.csv.gz" -exec mv {} FILEd_$(date ' %Y%m%d').csv.gz
from another post but get missing argument to -exec
error. Any examples using rename
or mv
for the above task please?
CodePudding user response:
Try something like this:
#! /bin/bash
declare -i i=0
for f in *.csv.gz; do
: $((i ))
mv "$f" "$(printf "FILEd_%s.csv.gz" $i "$(date %Y%m%d)")"
done