Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

71%
+3 −0
Q&A Rename multiple files which have a variable suffix

You can use rename for this. Many distributions package it; for example, it's apt-get install rename in Debian. In normal usage, it is used to apply an arbitrary regular expression substitution ex...

posted 7mo ago by Canina‭  ·  edited 7mo ago by Canina‭

Answer
#3: Post edited by user avatar Canina‭ · 2023-10-14T11:23:28Z (7 months ago)
  • You can use [rename](https://metacpan.org/dist/File-Rename) for this. Many distributions package it; for example, it's [apt-get install rename](https://packages.debian.org/bookworm/rename) in Debian.
  • It applies an arbitrary regular expression substitution expression to the name of each file named on the command line, allowing you to do complex renamings relatively easily. (It even supports using backreferences with `$1` through `$9` syntax for when you want to move parts of the file name around.)
  • Example:
  • $ cd $(mktemp -d)
  • $ touch IMG_20230917_093726_2-min.jpg-U2XlUA IMG_20230917_093726_2.jpg IMG_20230917_093738_3-min.jpg-H39QsD IMG_20230917_093738_3.jpg IMG_20230917_094057_1-min.jpg-AbxJMt IMG_20230917_094057_1.jpg
  • $ ls -1
  • IMG_20230917_093726_2.jpg
  • IMG_20230917_093726_2-min.jpg-U2XlUA
  • IMG_20230917_093738_3.jpg
  • IMG_20230917_093738_3-min.jpg-H39QsD
  • IMG_20230917_094057_1.jpg
  • IMG_20230917_094057_1-min.jpg-AbxJMt
  • $ rename -v 's,-......$,,g' *-min.jpg-*
  • IMG_20230917_093726_2-min.jpg-U2XlUA renamed as IMG_20230917_093726_2-min.jpg
  • IMG_20230917_093738_3-min.jpg-H39QsD renamed as IMG_20230917_093738_3-min.jpg
  • IMG_20230917_094057_1-min.jpg-AbxJMt renamed as IMG_20230917_094057_1-min.jpg
  • $ ls -1
  • IMG_20230917_093726_2.jpg
  • IMG_20230917_093726_2-min.jpg
  • IMG_20230917_093738_3.jpg
  • IMG_20230917_093738_3-min.jpg
  • IMG_20230917_094057_1.jpg
  • IMG_20230917_094057_1-min.jpg
  • $
  • You can use [rename](https://metacpan.org/dist/File-Rename) for this. Many distributions package it; for example, it's [apt-get install rename](https://packages.debian.org/bookworm/rename) in Debian.
  • In normal usage, it is used to apply an arbitrary regular expression substitution expression to the name of each file named on the command line, allowing you to do complex renamings relatively easily. (It even supports using backreferences with `$1` through `$9` syntax for when you want to move parts of the file name around.) It also supports a verbose mode (`-v`) which I use below, or a dry-run mode (`-n`) for when you want to see what it will do.
  • Example:
  • $ cd $(mktemp -d)
  • $ touch IMG_20230917_093726_2-min.jpg-U2XlUA IMG_20230917_093726_2.jpg IMG_20230917_093738_3-min.jpg-H39QsD IMG_20230917_093738_3.jpg IMG_20230917_094057_1-min.jpg-AbxJMt IMG_20230917_094057_1.jpg
  • $ ls -1
  • IMG_20230917_093726_2.jpg
  • IMG_20230917_093726_2-min.jpg-U2XlUA
  • IMG_20230917_093738_3.jpg
  • IMG_20230917_093738_3-min.jpg-H39QsD
  • IMG_20230917_094057_1.jpg
  • IMG_20230917_094057_1-min.jpg-AbxJMt
  • $ rename -v 's,-......$,,g' *-min.jpg-*
  • IMG_20230917_093726_2-min.jpg-U2XlUA renamed as IMG_20230917_093726_2-min.jpg
  • IMG_20230917_093738_3-min.jpg-H39QsD renamed as IMG_20230917_093738_3-min.jpg
  • IMG_20230917_094057_1-min.jpg-AbxJMt renamed as IMG_20230917_094057_1-min.jpg
  • $ ls -1
  • IMG_20230917_093726_2.jpg
  • IMG_20230917_093726_2-min.jpg
  • IMG_20230917_093738_3.jpg
  • IMG_20230917_093738_3-min.jpg
  • IMG_20230917_094057_1.jpg
  • IMG_20230917_094057_1-min.jpg
  • $
#2: Post edited by user avatar Canina‭ · 2023-10-14T11:22:15Z (7 months ago)
  • You can use [rename](https://metacpan.org/dist/File-Rename) for this. Many distributions package it; for example, it's [apt-get install rename](https://packages.debian.org/bookworm/rename) in Debian.
  • It applies an arbitrary regular expression substitution expression to the name of each file named on the command line, allowing you to do complex renamings relatively easily. (It even supports using backreferences with `\1` through `\9` syntax for when you want to move parts of the file name around.)
  • Example:
  • $ cd $(mktemp -d)
  • $ touch IMG_20230917_093726_2-min.jpg-U2XlUA IMG_20230917_093726_2.jpg IMG_20230917_093738_3-min.jpg-H39QsD IMG_20230917_093738_3.jpg IMG_20230917_094057_1-min.jpg-AbxJMt IMG_20230917_094057_1.jpg
  • $ ls -1
  • IMG_20230917_093726_2.jpg
  • IMG_20230917_093726_2-min.jpg-U2XlUA
  • IMG_20230917_093738_3.jpg
  • IMG_20230917_093738_3-min.jpg-H39QsD
  • IMG_20230917_094057_1.jpg
  • IMG_20230917_094057_1-min.jpg-AbxJMt
  • $ rename -v 's,-......$,,g' *-min.jpg-*
  • IMG_20230917_093726_2-min.jpg-U2XlUA renamed as IMG_20230917_093726_2-min.jpg
  • IMG_20230917_093738_3-min.jpg-H39QsD renamed as IMG_20230917_093738_3-min.jpg
  • IMG_20230917_094057_1-min.jpg-AbxJMt renamed as IMG_20230917_094057_1-min.jpg
  • $ ls -1
  • IMG_20230917_093726_2.jpg
  • IMG_20230917_093726_2-min.jpg
  • IMG_20230917_093738_3.jpg
  • IMG_20230917_093738_3-min.jpg
  • IMG_20230917_094057_1.jpg
  • IMG_20230917_094057_1-min.jpg
  • $
  • You can use [rename](https://metacpan.org/dist/File-Rename) for this. Many distributions package it; for example, it's [apt-get install rename](https://packages.debian.org/bookworm/rename) in Debian.
  • It applies an arbitrary regular expression substitution expression to the name of each file named on the command line, allowing you to do complex renamings relatively easily. (It even supports using backreferences with `$1` through `$9` syntax for when you want to move parts of the file name around.)
  • Example:
  • $ cd $(mktemp -d)
  • $ touch IMG_20230917_093726_2-min.jpg-U2XlUA IMG_20230917_093726_2.jpg IMG_20230917_093738_3-min.jpg-H39QsD IMG_20230917_093738_3.jpg IMG_20230917_094057_1-min.jpg-AbxJMt IMG_20230917_094057_1.jpg
  • $ ls -1
  • IMG_20230917_093726_2.jpg
  • IMG_20230917_093726_2-min.jpg-U2XlUA
  • IMG_20230917_093738_3.jpg
  • IMG_20230917_093738_3-min.jpg-H39QsD
  • IMG_20230917_094057_1.jpg
  • IMG_20230917_094057_1-min.jpg-AbxJMt
  • $ rename -v 's,-......$,,g' *-min.jpg-*
  • IMG_20230917_093726_2-min.jpg-U2XlUA renamed as IMG_20230917_093726_2-min.jpg
  • IMG_20230917_093738_3-min.jpg-H39QsD renamed as IMG_20230917_093738_3-min.jpg
  • IMG_20230917_094057_1-min.jpg-AbxJMt renamed as IMG_20230917_094057_1-min.jpg
  • $ ls -1
  • IMG_20230917_093726_2.jpg
  • IMG_20230917_093726_2-min.jpg
  • IMG_20230917_093738_3.jpg
  • IMG_20230917_093738_3-min.jpg
  • IMG_20230917_094057_1.jpg
  • IMG_20230917_094057_1-min.jpg
  • $
#1: Initial revision by user avatar Canina‭ · 2023-10-14T11:19:58Z (7 months ago)
You can use [rename](https://metacpan.org/dist/File-Rename) for this. Many distributions package it; for example, it's [apt-get install rename](https://packages.debian.org/bookworm/rename) in Debian.

It applies an arbitrary regular expression substitution expression to the name of each file named on the command line, allowing you to do complex renamings relatively easily. (It even supports using backreferences with `\1` through `\9` syntax for when you want to move parts of the file name around.)

Example:

    $ cd $(mktemp -d)
    $ touch IMG_20230917_093726_2-min.jpg-U2XlUA IMG_20230917_093726_2.jpg IMG_20230917_093738_3-min.jpg-H39QsD IMG_20230917_093738_3.jpg IMG_20230917_094057_1-min.jpg-AbxJMt IMG_20230917_094057_1.jpg
    $ ls -1
    IMG_20230917_093726_2.jpg
    IMG_20230917_093726_2-min.jpg-U2XlUA
    IMG_20230917_093738_3.jpg
    IMG_20230917_093738_3-min.jpg-H39QsD
    IMG_20230917_094057_1.jpg
    IMG_20230917_094057_1-min.jpg-AbxJMt
    $ rename -v 's,-......$,,g' *-min.jpg-*
    IMG_20230917_093726_2-min.jpg-U2XlUA renamed as IMG_20230917_093726_2-min.jpg
    IMG_20230917_093738_3-min.jpg-H39QsD renamed as IMG_20230917_093738_3-min.jpg
    IMG_20230917_094057_1-min.jpg-AbxJMt renamed as IMG_20230917_094057_1-min.jpg
    $ ls -1
    IMG_20230917_093726_2.jpg
    IMG_20230917_093726_2-min.jpg
    IMG_20230917_093738_3.jpg
    IMG_20230917_093738_3-min.jpg
    IMG_20230917_094057_1.jpg
    IMG_20230917_094057_1-min.jpg
    $