Post History
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...
Answer
#3: Post edited
- 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
- 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
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 $