-3

How we can bulk rename multiple files? What I seek is a regex approach to remove random characters from the beginning of the filenames?

For example suppose I have the following files in a directory

_3cc10c0294ce15295e17e737a1d4dde1_C1W2L08.pptx
_7beaa0a223aca1d64505e8382275bb8e_C1W2L09-2.05.53-PM.pptx
_090fd2695e7f30570037a0fae658035a_C1W2L07.pptx

and here is what i intend to see:

C1W2L08.pptx
C1W2L09-2.05.53-PM.pptx
C1W2L07.pptx
sci9
  • 700
  • 1
  • 7
  • 21

3 Answers3

0

Use rename

rename 's/_.{32}_//' *.pptx

Deletes the underscores and the 32 characters between them.

pacholik
  • 8,607
  • 9
  • 43
  • 55
0
for i in *.pptx
do
  mv $i ${i#_*_}
done

#{var#prefix} will remove the prefix; * matches a sequence of characters. See more at man bash, look for "Parameter Expansion".

Amadan
  • 191,408
  • 23
  • 240
  • 301
0

This code will select all the files of a similar structure and remove their prefix.

for file in _[a-z0-9]*pptx; do
       mv -- "$file" "${file/_*_/}";
done