Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
Renaming files in subfolders using zmv

Let's say I want to rename all the files inside all the subfolders of a folder from foo.txt to bar.txt using zmv.

I've tried zmv '**/foo.txt' 'bar.txt' but this creates bar.txt in the root folder. How can I keep the files in their corresponding subfolder?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You need to reference the directory part in the target. You can do that by putting the wildcards in parentheses and using $1 to refer to the part matched by the parenthetical group. The ** wildcard is a little special and requires that the parentheses are around **/, no more, no less.

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

You can use the -w flag to have each wildcard automatically made into a parenthetical group.

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

Or you can use the -W flag and use wildcards in the replacement text — with this flag, the wildcards in the replacement text are turned into $1, $2, etc.

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

Alternatively, you can use $f to refer to the source path.

zmv '**/foo.txt' '$f:r.txt'
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda