12

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.

karel
  • 13,706

1 Answers1

13
  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.

karel
  • 13,706