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,390
  • 26
  • 45
  • 52
Andrew Brown
  • 223
  • 1
  • 2
  • 4
  • You actually mean 'rename' instead of 'convert', I believe. Are you looking for a product suggestion? That'd be off-topic here. Are you looking for a script? If so, you should post what you have so far, because SuperUser isn't a script-writing service. – ChrisInEdmonton Jan 09 '16 at 13:43
  • It is, apparently, and sadly. – user1016274 Jan 09 '16 at 13:49
  • This has been asked to many times that we even have a tag for it. Looking for the best duplicate and VTC close. – Hennes Jan 09 '16 at 14:29
  • http://superuser.com/questions/412450/batch-rename-files-in-linux http://superuser.com/questions/298407/how-can-i-batch-rename-a-set-of-filenames-in-linux http://superuser.com/questions/712071/how-to-batch-rename-long-file-names-into-short-ones-under-linux http://superuser.com/questions/658030/renaming-multiple-files-at-once-with-a-pattern-on-ubuntu http://superuser.com/questions/220960/batch-renaming-of-files-in-a-directory-using-sed – Hennes Jan 09 '16 at 14:33

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,390
  • 26
  • 45
  • 52