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

mod rewrite - Using "?" when rewriting the URL -

.htaccess: Transfer name to index.php if not directory public -

Admob integration with pygame in android -