Bash: Recursively adding an extension to all files without extensions

January 16, 2013

While attempting to import an existing website to WordPress I noticed that the local copy of the website I had created with wget –mirror did not have any file extensions. This makes sense because the URL did not have an extension in it. The HTML import tool requires and extension however. The following command will recursively look through each directory for files without extensions and add an extension to them.

for file in $( find . -type f | grep -v .\\. ) ; do mv "$file" "$file".html ; done

Note: This command does not seem to work on files with spaces in the filename

Thanks to Pio and my Linux group for help getting the command right