Bijan Bijan - 11 months ago 40
Bash Question

Shell Script: Copy Multiple Files and add Timestamp

I have a folder that contains a few

files and I am trying to create a shell script that copies every
file but adds the current date to the file

For example, the folder contains
. I want it to copy
and so on.

I know I can do
cp -a A.db /Backups/A.db
but I am looking for a more automated way to do it for every
file and also add the current date


Iterate over the files using a for construct and cp files to the destination with getting desired file names using bash parameter expansion and date:

for f in *.db; do cp -a "$f" /Backups/""${f%.db}"_$(date '+%Y_%m_%d').db"; done