Skip to main content
added 60 characters in body
Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k

Your rename seems to be the useless one from util-linux.

You'd want to make sure one of the perl-based variants is installed instead (sometimes called prename) if you want to use regular expressions. And then:

rename -n 's:^\./\d+(?=\d{44}\.xml\Z)::' ./*.xml 

(here replacing your 48 characters, with 44 digits followed by .xml so as to be more specific).

Alternatively, you could use zsh's zmv:

autoload zmv zmv -n '[0-9]##([0-9](#c44).xml)' '$1' 

Or

zmv -n '<->.xml~^?(#c48)' '$f[-48,-1]' 

(remove -n (dry-run) to actually do it).

Which also has the benefit of guarding against conflicts (two files having the same destination name)

With bash, you could do something like:

shopt -s extglob nullglob for f in +([[:digit:]]).xml; do ((${#f) <= 48)) || echo mv -i -- "$f" "${f: -48}" done 

Your rename seems to be the useless one from util-linux.

You'd want to make sure one of the perl-based variants is installed instead (sometimes called prename) if you want to use regular expressions. And then:

rename -n 's:^\./\d+(?=\d{44}\.xml\Z)::' ./*.xml 

(here replacing your 48 characters, with 44 digits followed by .xml so as to be more specific).

Alternatively, you could use zsh's zmv:

autoload zmv zmv -n '[0-9]##([0-9](#c44).xml)' '$1' 

(remove -n (dry-run) to actually do it).

Which also has the benefit of guarding against conflicts (two files having the same destination name)

With bash, you could do something like:

shopt -s extglob nullglob for f in +([[:digit:]]).xml; do ((${#f) <= 48)) || echo mv -i -- "$f" "${f: -48}" done 

Your rename seems to be the useless one from util-linux.

You'd want to make sure one of the perl-based variants is installed instead (sometimes called prename) if you want to use regular expressions. And then:

rename -n 's:^\./\d+(?=\d{44}\.xml\Z)::' ./*.xml 

(here replacing your 48 characters, with 44 digits followed by .xml so as to be more specific).

Alternatively, you could use zsh's zmv:

autoload zmv zmv -n '[0-9]##([0-9](#c44).xml)' '$1' 

Or

zmv -n '<->.xml~^?(#c48)' '$f[-48,-1]' 

(remove -n (dry-run) to actually do it).

Which also has the benefit of guarding against conflicts (two files having the same destination name)

With bash, you could do something like:

shopt -s extglob nullglob for f in +([[:digit:]]).xml; do ((${#f) <= 48)) || echo mv -i -- "$f" "${f: -48}" done 
added 1 character in body
Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k

Your rename seems to be the useless one from util-linux.

You'd want to make sure one of the perl-based variants is installed instead (sometimes called prename) if you want to use regular expressions. And then:

rename -n 's:^\./\d+(?=\d{44}\.xml\Z)::' ./*.xml 

(here replacing your 48 characters, with 44 digits followed by .xml so as to be more specific).

Alternatively, you could use zsh's zmv:

autoload zmv zmv -n '[0-9]##([0-9](#c44).xml)' '$1' 

(remove -n (dry-run) to actually do it).

Which also has the benefit of guarding against conflicts (two files having the same destination name)

With bash, you could do something like:

shopt -s extglob nullglob for f in +([[:digit:]]).xml; do ((${#f) <= 48)) || echo mv -i -- "$f" "${f: -48}" done 

Your rename seems to be the useless one from util-linux.

You'd want to make sure one of the perl-based variants is installed instead (sometimes called prename) if you want to use regular expressions. And then:

rename -n 's:^\./\d+(?=\d{44}\.xml\Z)::' ./*.xml 

(here replacing your 48 characters, with 44 digits followed by .xml so as to be more specific).

Alternatively, you could use zsh's zmv:

autoload zmv zmv -n '[0-9]##([0-9](#c44).xml)' '$1' 

(remove -n (dry-run) to actually do it).

Your rename seems to be the useless one from util-linux.

You'd want to make sure one of the perl-based variants is installed instead (sometimes called prename) if you want to use regular expressions. And then:

rename -n 's:^\./\d+(?=\d{44}\.xml\Z)::' ./*.xml 

(here replacing your 48 characters, with 44 digits followed by .xml so as to be more specific).

Alternatively, you could use zsh's zmv:

autoload zmv zmv -n '[0-9]##([0-9](#c44).xml)' '$1' 

(remove -n (dry-run) to actually do it).

Which also has the benefit of guarding against conflicts (two files having the same destination name)

With bash, you could do something like:

shopt -s extglob nullglob for f in +([[:digit:]]).xml; do ((${#f) <= 48)) || echo mv -i -- "$f" "${f: -48}" done 
added 1 character in body
Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k

Your rename seems to be the useless one from util-linux.

You'd want to make sure one of the perl-based variants is installed instead (sometimes called prename) if you want to use regular expressions. And then:

rename -n 's:^\./\d+(?=\d{44}\.xml\Z)::' ./*.xml 

(here replacing your 48 characters, with 44 digits followed by .xml so as to be more specific).

Alternatively, you could use zsh's zmv:

autoload zmv zmv -n '[0-9]##([0-9](#c44).xml)' '$1' 

(remove -n (dry-run) to actually do it).

Your rename seems to be the useless one from util-linux.

You'd want to make sure one of the perl-based variants is installed instead (sometimes called prename) if you want to use regular expressions. And then:

rename -n 's:^\./\d+(?=\d{44}\.xml\Z)::' ./*.xml 

(here replacing your 48 characters, with 44 digits followed by .xml so as to be more specific).

Alternatively, you could use zsh's zmv:

autoload zmv zmv -n '[0-9]##([0-9](#c44.xml)' '$1' 

(remove -n (dry-run) to actually do it).

Your rename seems to be the useless one from util-linux.

You'd want to make sure one of the perl-based variants is installed instead (sometimes called prename) if you want to use regular expressions. And then:

rename -n 's:^\./\d+(?=\d{44}\.xml\Z)::' ./*.xml 

(here replacing your 48 characters, with 44 digits followed by .xml so as to be more specific).

Alternatively, you could use zsh's zmv:

autoload zmv zmv -n '[0-9]##([0-9](#c44).xml)' '$1' 

(remove -n (dry-run) to actually do it).

Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k
Loading