Search code examples
bashshellredhat

bash/terminal RH remove last 3 characters of filename


I have thousands of images in a folder and subdirectories, I tried to create a compress file of them all. Somehow I have inadvertently added .gz to the end of every image.

image1.jpg.gz
image2.jpg.gz
/Folder/image3.jpg.gz

Im trying to find the correct command to remove all of the .gz extension and keep the .jpg extension.

Any help greatly appreciated.


Solution

  • This should work probably.

    find . -name '*.gz' -exec bash -c 'mv "${1%%.gz}"{.gz,}' - {} \;