Reputation: 105
When I execute this command on my server :
cp *index.html saveIndex/$(date +%Y%m%d-%H%M)Index.html
The shell indicates :
cp: target 'saveIndex/20180110-0934Index.html' is not a directory
However, this command function on my computer.
Upvotes: 3
Views: 6084
Reputation: 1838
Because you have multiple *index
files, and your command looks like:
cp index.html 1index.html bla-blaindex.html saveIndex/20180110-0934Index.html
and it could be executed if only last argument is a directory, not file name.
You can or run cp *index.html saveIndex/
, or add seconds at the date
for new filename and create the script like that:
#!/bin/bash
for ifile in *index.html
do
cp "${ifile}" saveIndex/$(date +%Y%m%d-%H%M%S)Index.html
sleep 1
done
sleep 1
will allows you to get unique names, but you can use any another suffix you prefer ($RANDOM
for example or last time modified/changed date, inode of each file) to avoid sleep 1
waiting.
Inode example:
#!/bin/bash
for ifile in *index.html
do
cp "${ifile}" saveIndex/$(stat -c %i "${ifile}")-$(date +%Y%m%d-%H%M%S)Index.html
done
Upvotes: 4