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
Post a Comment