linux - Renaming files in subfolders using zmv -


let's want rename files inside subfolders of folder foo.txt bar.txt using zmv.

i've tried zmv '**/foo.txt' 'bar.txt' creates bar.txt in root folder. how can keep files in corresponding subfolder?

you need reference directory part in target. can putting wildcards in parentheses , using $1 refer part matched parenthetical group. ** wildcard little special , requires parentheses around **/, no more, no less.

zmv '(**/)foo.txt' '${1}bar.txt' 

you can use -w flag have each wildcard automatically made parenthetical group.

zmv -w '**/foo.txt' '${1}bar.txt' 

or can use -w flag , use wildcards in replacement text — with flag, wildcards in replacement text turned $1, $2, etc.

zmv -w '**/foo.txt' '**/bar.txt' 

alternatively, can use $f refer source path.

zmv '**/foo.txt' '$f:r.txt' 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -