Search code examples
linuxshellrenamemv

Rename Linux files by removing characters after extensions


I would like to rename all .jpg files in a folder on Linux through one line in the terminal. The filenames all end with numbers ranging from one to three digits. I would like to get rid of the numbers at the end of the file extension.

From:

file1.jpg62
file2.jpg193
file3.jpg3

To:

file1.jpg
file2.jpg
file3.jpg

What would a rename or mv command look like to do this?


Solution

  • strip the extension and just add it after match.

    for i in * ; do mv "${i}" "${i%%.*}.jpg" ; done
    

    this is for the usercase above only. it doesn't consider having duplicate files etc.