Ubuntu – Copy file to same directory with appended filename Via SSH Bash Script

bashscriptsssh

How would I copy a batch of files into the same directory with an appended filename via SSH Bash Script?
For example.

/path/files/file /path/files/file-20120105

The trick is for it to be a one liner so I don't have to do any fancy for loop or some other mechanism to pass it via ssh.

Best Answer

You can do

cp /path/files/file /path/files/file-$(date +%Y%m%d) 

To do the same for multiple files e direcories:

timestamp=$(date +%Y%m%d)
for f in /path/files/*; do
    cp -a "$f" "$f-$timestamp"
done