linux - How to copy files from dir and append date to filename? -


i'm trying copy files 1 directory , append current date filename. script this

#!/bin/bash  echo 'move homedir' cd $home  echo 'copy .txt files' now=$(date +"%d%m%y")  filename in *.txt         cp "${filename}" "/newdir/${filename}${now}" done 

this generates error because date appended after file extension, this

file1.txt10082013

how avoid that?

how extracting extension , renaming file:

name="${filename%.*}" ext="${filename##*.}  cp "${filename}" "/newdir/${name}${now}.${ext}" 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -