Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 12035  / 2 Years ago, sat, september 3, 2022, 5:27:08

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.


More From » bash

 Answers
2

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

[#41110] Saturday, September 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sipwing

Total Points: 245
Total Questions: 100
Total Answers: 118

Location: Aland Islands
Member since Thu, Oct 22, 2020
4 Years ago
sipwing questions
Sun, May 29, 22, 22:00, 2 Years ago
Fri, Jun 24, 22, 08:46, 2 Years ago
Fri, Dec 23, 22, 00:04, 1 Year ago
;