echo - how to change part of a file name to something else on mutilple files - Ask Ubuntu


i'm making game learn commands , have directories have same number of files of different types in them. need able change part of file name in each directory signifies in deed file directory.

e.g,

dir 1 name "orange" file 1 name: "water_orange.jpeg" file 2 name: 1_water_orange.jpeg" etc, etc 15 files

dir 2 name "indigo" file 1 name: "water_indigo.jpeg" file 2 name: "1_water_indigo.jpeg" etc etc 15 files

i have 7 directories 15 files in each , want see if it's possible change colour part of file name in each directory, without have use "mv" command on each individual file.

i've tried "echo sed" command both single , double quotes no luck

i.e. echo sed "s/orange/indigo/g" , echo sed 's/orange/indigo/g'

any sincerely appreciated

something following should work:

for in $(ls *.jpeg)  mv -v $i $(ls $i | sed 's/orange/indigo/') done 

but very clumsy syntax can enormously improved, steeldriver has suggested in comments below, following elegant syntax:

for in *.jpeg; mv -v -- "$i" "${i/orange/indigo}"; done 

bear in mind both of these examples single directories, , not recursive...


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User