Reputation: 47
So I'm battling with a script at the moment. I'm using zsh. I've tried various combinations, but not coming right. Trying to change file names recursively. So basically I have a variable: file1. What I'm trying to do is something like this:
zmv -W ${file1}/'**/*(test)*' ${file1}/'**/*red*'
This should change any file or folder in subdirectories recursively from test to red. Hence: if $file1= /var/log then it should change:
/var/log/jump/greentest.txt to /var/log/jump/greenred.txt
also
/var/log/jump/1/1/test/test.xyz to /var/log/jump/1/1/red/red.xyz
Basically if I did a search:
ls **/*test*
it would list all the files and folders recursively that had the word 'test' contained within them. With the zmv solution, I'd like to "find" those instances and change test to red.
How can I do this?
Upvotes: 1
Views: 627
Reputation: 22291
I hope you try these things first with -n
....
Aside from this, the only part which looks wrong to me are the parenthesis around test
. You introduce a new pattern variable for something which is not a wildcard, but your -W
alreay implicitly introduces groups and references. Hence I would try it with
zmv -Wn $file1/'**/*test*' $file1/'**/*red*'
and if it works, remove the -n
.
Upvotes: 1