I have over 100,000 images in a complicated folder structure similar to the one below:

├── folder1
│   ├── 0001.jpeg
│   └── 0002.jpeg
├── folder2
│   ├── 0001.jpeg
│   └── 0002.jpeg
├── folder3
│    └── folder4
│         ├── 0001.jpeg
│         └── 0002.jpeg
└── folder5
     └── folder6
           └── folder7
                ├── 0001.jpeg
                └── 0002.jpeg   

I would like to keep the folder structure unchanged but I would like to rename each of the .jpeg files to .jpg files (.jpeg->.jpg)

My downstream commands require .jpg files, and attempting to change that code to simply handle the .jpeg files has been unsuccessful.


1 Answer 1

  1. Open the terminal.

  2. Change directory to the parent directory of folder1 using the cd command.

    cd /path/to/parent/directory/of/folder1/
  3. Run this command to rename all files with .jpeg extension to .jpg.

    find . -type f -name '*.jpeg' -print0 | xargs -0 rename 's/\.jpeg/\.jpg/'

The above command uses the Perl rename program which is installed by default in Debian-based operating systems. In some other Linux distributions, the same Perl rename program is called prename. prename can be installed by following the instructions from: Get the Perl rename utility instead of the built-in rename.

  • It looks like you can use the same command but use mv instead of rename Jun 7, 2019 at 9:08
  • The mv does not work here. On Ubuntu, at least, you can use "rename.ul .jpeg .jpg *.jpeg" in a single directory.
    – crafter
    Jul 13, 2020 at 22:49
  • 1
    For example, within Alpine Linux: apk update && apk add make perl-utils && cpan File::Rename will install the Perl version of rename. Feb 13, 2023 at 14:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .