I am trying to prefix timestamp and add an extension to files using a script. I have file ABC which I is being renamed to ABC.txt
DIRECTORY=`find /path/to/file -type f ! -name "*.*"`
NOW=$(date +%Y-%m-%d-%H%M%S)
for file in $DIRECTORY; do
mv "$file" "$file"_"${NOW}.txt"
done
The output above works but as a suffix, if I switch it around
mv "$file" "${NOW}"$file".txt"
I'm getting cannot mv: cannot move`2019-10-18-231254/path/to/file/ABC.txt': No such file or directory
I can see the issue is with the $Directory as this is calling the full path when doing the mv. Could someone please help simplify this?
$file
contains the whole path and not just the filename. If everything is happening in the same folder, the filename should suffice - if not you'd also have to extract the path. Or maybesed
could help as well... – rudib Oct 18 '19 at 22:37