I'm trying to remove some strings from filenames i have in a directory using bash. I've tried the following with no success.
rename --version
rename from util-linux 2.23.2
rename -v 's/[.].*//' *
rename -v 's/\.vesta-01:2,//' *
Original File Name(s):
1667874526.M308257P1693.vesta-01:2,
1667883117.M371701P32232.vesta-01:2,
Desired File Name(s):
1667874526
1667883117
CodePudding user response:
rename
from util-linux
doesn't accept Perl substitution. See man 1 rename:
rename [options] expression replacement file...
You can use mv
in a loop with parameter expansion instead:
for f in *.vesta-01:2, ; do
mv "$f" "${f%%.*}"
done
CodePudding user response:
Try using mv
with bash parameter expansion instead:
$ ls 166*
1667874526.M308257P1693.vesta-01:2 1667883117.M371701P32232.vesta-01:2
$ f1="1667874526.M308257P1693.vesta-01:2" ; mv "$f1" "${f1%%.*}"
$ f2="1667883117.M371701P32232.vesta-01:2" ; mv "$f2" "${f2%%.*}"
$ ls 166*
1667874526 1667883117