Command for rename file as IMG0001 to 4R0001 in folder

for f in *;do mv "$f" `echo "$f" | sed 's/IMG/4R/g' `; done


I just want rename selected folder

/tmp/2014/1201 (rename files)
/tmp/2014/1224 (rename files)

find not good for selected folder

awk for selected folder by renamelist.txt but miss match with for loop $value



The more easy way is use bash substitution in this way:

for i in $(find . -name '*IMG*');do mv -v $i ${i//IMG/RG}; done
‘./IMG001.img’ -> ‘./RG001.img’
| improve this answer | |
  • 1
    Quote your variables... – jasonwryan Dec 18 '14 at 8:59
  • Thanks, Rename is fine, But I want to rename files by a name list renamelist.txt not all folder – Gary Lau Dec 18 '14 at 9:14
  • Gary Lau "find . -type f -name 'IMG'" in this way find command only works on files. – c4f4t0r Dec 18 '14 at 13:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.