Skip to main content
ITYM -w, not -q
Source Link
Stéphane Chazelas
  • 584.9k
  • 96
  • 1.1k
  • 1.7k

In zsh, put autoload zmv in your .zshrc (or run that one on your command line to experiment with it), then:

mkdir /home/user1/newfolder
zmv '/home/user/(*)/(*)/(cover.jpg)' '/home/user1/newfolder/${1}_${2}_${3}'

Every file that matches the pattern on the left-hand side is renamed to the replacement text on the right-hand side. * means “any sequence of characters”. On the right-hand side, ${1}, ${2} and ${3} are replaced respectively by the portion of the source path matched by the first, second and third parenthesised group in the pattern.

Instead of using explicit grouping, you can request each wildcard to be automatically made a group of its own:

zmv -qw '/home/user/*/*/cover.jpg' '/home/user1/newfolder/${1}_${2}_cover.jpg'

Or even:

zmv -W '/home/user/*/*/cover.jpg' '/home/user1/newfolder/*_*_cover.jpg'

Some even go as far as adding:

alias zmmv='noglob zmv -W'

to there ~/.zshrc so as to be able to write:

zmmv /home/user/*/*/cover.jpg /home/user1/newfolder/*_*_cover.jpg

In zsh, put autoload zmv in your .zshrc (or run that one on your command line to experiment with it), then:

mkdir /home/user1/newfolder
zmv '/home/user/(*)/(*)/(cover.jpg)' '/home/user1/newfolder/${1}_${2}_${3}'

Every file that matches the pattern on the left-hand side is renamed to the replacement text on the right-hand side. * means “any sequence of characters”. On the right-hand side, ${1}, ${2} and ${3} are replaced respectively by the portion of the source path matched by the first, second and third parenthesised group in the pattern.

Instead of using explicit grouping, you can request each wildcard to be automatically made a group of its own:

zmv -q '/home/user/*/*/cover.jpg' '/home/user1/newfolder/${1}_${2}_cover.jpg'

In zsh, put autoload zmv in your .zshrc (or run that one on your command line to experiment with it), then:

mkdir /home/user1/newfolder
zmv '/home/user/(*)/(*)/(cover.jpg)' '/home/user1/newfolder/${1}_${2}_${3}'

Every file that matches the pattern on the left-hand side is renamed to the replacement text on the right-hand side. * means “any sequence of characters”. On the right-hand side, ${1}, ${2} and ${3} are replaced respectively by the portion of the source path matched by the first, second and third parenthesised group in the pattern.

Instead of using explicit grouping, you can request each wildcard to be automatically made a group of its own:

zmv -w '/home/user/*/*/cover.jpg' '/home/user1/newfolder/${1}_${2}_cover.jpg'

Or even:

zmv -W '/home/user/*/*/cover.jpg' '/home/user1/newfolder/*_*_cover.jpg'

Some even go as far as adding:

alias zmmv='noglob zmv -W'

to there ~/.zshrc so as to be able to write:

zmmv /home/user/*/*/cover.jpg /home/user1/newfolder/*_*_cover.jpg
Source Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k

In zsh, put autoload zmv in your .zshrc (or run that one on your command line to experiment with it), then:

mkdir /home/user1/newfolder
zmv '/home/user/(*)/(*)/(cover.jpg)' '/home/user1/newfolder/${1}_${2}_${3}'

Every file that matches the pattern on the left-hand side is renamed to the replacement text on the right-hand side. * means “any sequence of characters”. On the right-hand side, ${1}, ${2} and ${3} are replaced respectively by the portion of the source path matched by the first, second and third parenthesised group in the pattern.

Instead of using explicit grouping, you can request each wildcard to be automatically made a group of its own:

zmv -q '/home/user/*/*/cover.jpg' '/home/user1/newfolder/${1}_${2}_cover.jpg'