Reputation: 41
mv
command is unable to find the file that I'm trying to rename.
I've looked to solutions involving double quotes, directory expansion and variable evaluation but nothing explains why this Bash script won't work.
I've also confirmed that the path is correct and the file exists. If anyone could help I would greatly appreciate it.
Below is the code in question with an explanation:
BASEPATH="/media/matt/DATA/Flow_Processing/fvv/rafa_1_ifsc/STEA_flow/"
FRSTFRM=00030
LSTFRM=00270
FRSTCAM=001
LSTCAM=012
for cam in $(eval echo "{$FRSTCAM..$LSTCAM}")
do
for frame in $(eval echo "{$FRSTFRM..$LSTFRM}")
do
SRC="${BASEPATH}${cam}/flow/FVV_0_${cam}_${frame}_flow.flo"
DST="${BASEPATH}${cam}/flow/FVV_2_${cam}_$frame.flo"
mv -f $SRC $DST
done
done
So essentially I'm trying to iterate through a file system structure using $cam
and $frame
variables which are padded strings.
I'm trying to change the filenames in each of these folders from:
FVV_0_<cam num>_<frame num>_flow.flo
to
FVV_2_<cam num>_<frame num>.flo
e.g. for camera 1 and frame 1 the file changes from:
FVV_0_001_00001_flow.flo
to
FVV_2_001_00001.flo
I've printed $SRC
and $DST
and they output the exact path that I expect. The problem is that in spite of this, mv
produces this error:
"cannot stat: <file> : no such file or directory"
e.g.
SRC:
/media/matt/DATA/Flow_Processing/fvv/rafa_1_ifsc/STEA_flow/005/flow/FVV_0_005_00190_flow.flo
DST:
/media/matt/DATA/Flow_Processing/fvv/rafa_1_ifsc/STEA_flow/005/flow/FVV_2_005_00190.flo
mv
error:
mv: cannot stat '/media/matt/DATA/Flow_Processing/fvv/rafa_1_ifsc/STEA_flow/005/flow/FVV_0_005_00190_flow.flo': No such file or directory
Upvotes: 2
Views: 12076
Reputation: 41
I solved it by fixing an error in write permissions with mounted media.
My /etc/fstab
file required me to add "vers=1.0"
at the end of the mount options for my NAS media drive.
Thanks to the help from @Azeem who helped me realize that I hadn't got permission to access files on the drive.
Upvotes: 2