I want add the date next to a filename ("somefile.txt"). For example: somefile_DDMMYYYYHHMMSS.txt
Maybe a script will do or some command in the terminal window. I'm using Linux.
Thanks in advance.
Something like can do the work:
a=somefile.txt
bname="${a%.*}"
ename="${a##*.}"
date=$(date +%d%m%Y%H%M%S)
echo ${bname}_${date}.${ename}
You can also try this.
#!/bin/bash -e
TDATE=$(date +%d%m%Y%H%M%S)
for FULLFILE in `ls`
do
FILENAME=`echo $FULLFILE | cut -d '.' -f1`
EXTN=`echo $FULLFILE | cut -d '.' -f2`
mv ${FULLFILE} ${FILENAME}_${TDATE}.${EXTN}
done
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.