recursively add file extension to all files
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.
this will find files without extension and add your .jpg
find /path -type f -not -name "*.*" -exec mv "{}" "{}".jpg \;
This is a little late, but I thought I would add that a better solution (although maybe less readable) than the ones so far might be:
find /path -type f -not -name "*.*" -print0 | xargs -0 rename 's/(.)$/$1.jpg/'
Using the find | xargs
pattern generally results in more efficient execution, as you don't have to fork a new process for each file.
Note that this requires the version of rename found in Debian-flavored distros (aka prename), rather than the traditional rename. It's just a tiny perl script, though, so it would be easy enough to use the command above on any system.