recursively add file extension to all files


Question

I have a few directories and sub-directories containing files with no file extension. I want to add .jpg to all the files contained within these directories. I've seen bash scripts for changing the file extension but not for just adding one. It also needs to be recursive, can someone help please?

1
101
4/19/2010 9:03:17 PM

Accepted Answer

Alternative command without an explicit loop (man find):

find . -type f -exec mv '{}' '{}'.jpg \;

Explanation: this recursively finds all files (-type f) starting from the current directory (.) and applies the move command (mv) to each of them. Note also the quotes around {}, so that filenames with spaces (and even newlines...) are properly handled.

217
7/10/2009 9:24:01 AM

this will find files without extension and add your .jpg

find /path -type f -not -name "*.*" -exec mv "{}" "{}".jpg \;

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon