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
Post a Comment