<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Nov 21, 2013 at 4:54 PM, David Goodwin <span dir="ltr"><<a href="mailto:david@codepoets.co.uk" target="_blank">david@codepoets.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im"><br>
On 21 Nov 2013, at 16:30, Suntish Narain <<a href="mailto:suntish@googlemail.com">suntish@googlemail.com</a>> wrote:<br>
<br>
> Hi<br>
><br>
> I have a situation where I have several files, say file1.txt, file2.txt, file3.txt and file4.txt (but the number of files can change!) that I want to move from the source folder to a target folder. The only difference is that I want the files in the target folder to have todays' date appended to it, so would be file1_20131121.txt, file2_20131121.txt.., file4_20131121.txt<br>
><br>
> I thought<br>
> cp /home/user/Documents/source/file* /home/user/Documents/target/file*_$(date +%Y%m%d).txt would work but no.. it says directory does not exist..<br>
><br>
> but<br>
> mv /home/user/Documents/source/file1.txt /home/user/Documents/target/file1_$(date +%Y%m%d).txt works<br>
<br>
<br>
</div>I think you have to do it something like :<br>
<br>
for file in /path/to/source/file*<br>
do<br>
shortFileName=$(basename $file .txt)<br>
mv $file /path/to/somewhere/else/$shortFileName_$(date +%F).txt<br>
done<br>
<br>
Note, this won't work if you have any spaces in your file names (it'll fail miserably), but you indicate that you're only interested in file1.txt, file2.txt etc which is ok.<br>
<br>
<br>
David.<br></blockquote><div><br></div><div>Or something like:<br><br>find ./src/ -type f | while read f; do<br> cp "$f" "./dst/$(basename $f .txt)_$(date +%F).txt"<br>done<br><br></div><div>My tip, would be don't script with a 'mv' until you know your script works!<br>
<br></div><div>Chris<br></div></div><br></div></div>