简体   繁体   中英

My mv command is showing no such file or directory when renaming a file

In the below code I am renaming a file with a date field addition to it.but the error says no such file or directory.its doing the moving operation instead of renaming it. Thanks.

#!bin/bash

cd /some/directory/name

LIST=$(ls)

for FILE in $LIST
do
 DATE=$(date +%d%m%y%H%M%S)
 VARX=$(echo $FILE | cut - d '.' -f 1)
 VARY=$(echo $FILE | cut - d '.' -f 2)
NNAME="${VARX}""${DATE}"."${VARY}"

mv "${FILE}" "${NNAME}";
done

you missed a space when using the cut command, instaed of - d you should write -d like

#!bin/bash

cd /some/directory/name

LIST=$(ls)

for FILE in $LIST
do
 DATE=$(date +%d%m%y%H%M%S)
 VARX=$(echo $FILE | cut -d '.' -f 1)
 VARY=$(echo $FILE | cut -d '.' -f 2)
NNAME="${VARX}""${DATE}"."${VARY}"

mv "${FILE}" "${NNAME}";
done

Have a good day !

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM