1

I am trying to rename all files in a directory using mv but it isn't working. My code is:

id= '29 10 15'
for zzvar in ${id} ; do
  mv /media/storage/DTI/vgcross_sj${var}* /media/storage/DTI/vgcross_SJ${var}*
done

Even when I take the loop out and just try the command with one subject, I get the error:

mv: target:/media/storage/DTI/vgcross_SJ  is not a directory.

Obviously it's not a directory, because that's what I'm trying to rename the file as! Do you have any ideas as to why it's not working?

David Foerster
  • 36,264
  • 56
  • 94
  • 147
  • 1
    You are using * there, which expands to multiple files, including directories. So after expansion you what mv command will see is a whole list of items that you're trying to move somewhere, and it's not a directory. In general, your script looks a bit messy, id= '29 10 15' shouldn't have space after = sign, within script you're referencing ${var}, while your loop uses zzvar – Sergiy Kolodyazhnyy Jul 17 '17 at 14:25
  • Is there a way I can include all files that begin with vgcross_sj without including the directories? In other words, a similar function to using * that it would understand?

    Thank you!

    – jbenady Jul 18 '17 at 10:59

0 Answers0