I have a folder full of jpegs formatted like this:
0001_20210516_XYZ.jpg
0002_20210516_XYZ.jpg
123_20210516_XYZ.jpg
01_20210516_XYZ.jpg
and I want to rename all files so the date string in the middle is removed so the files look like:
0001_XYZ.jpg
0002_XYZ.jpg
123_XYZ.jpg
01_XYZ.jpg
I tried using this answer to write the regex to remove 8 digits using this code:
rename - 's/^_\d{8}\_//' *
But this did not do anything. I am not sure how to format this correctly so the middle date string is removed.
Usage: rename [options] expression replacement file...
Options: -v, --verbose explain what is being done -s, --symlink act on symlink target
-h, --help display this help and exit -V, --version output version information and exit
For more details see rename(1). ` and when I run it without -n my filenames don't change :(
– Pad Jun 16 '21 at 16:49rename
that you are using is not one that I am familiar with - my answer applies to the Perl-based one sometimes known asfile-rename
. – steeldriver Jun 16 '21 at 16:57rename from util-linux 2.23.2
thank you for your help! I will keep trying. – Pad Jun 16 '21 at 17:00prename
– glenn jackman Jun 16 '21 at 17:44rename -v "_$(date +%Y%m%d)" '' *_*_*.jpg
– Pad Jun 17 '21 at 11:11