Ubuntu – Append text to file names which do not contain a dot

batch-renamecommand linerename

Given the following files:

english_api
english_overview
style.css

I want to get:

english_api.html
english_overview.html
style.css

In other words how to append a text to all files that do Not Contain a dot (.) within a directory using terminal.

Obviously there is a lot of files in that folder; I just wrote 3 as an example.

If I were to, lets say, replace .css with .html in that folder, I would use:

rename .css .html *.css

But I cannot really think of a way to match files that do not contain something. Also how to append (vs replace) using rename command?

Best Answer

Try this find command,

find . -type f ! -name "*.*" -exec mv {} {}.html \;

It renames the files which doesn't contain dots in their filenames present in the current directory to this filename.htmlformat(added .html at the last).

. --> Represents current directory

-type f --> To do this operation only on files.

! -name "*.*" --> print the name of the files which doesn't have dots in their name.

-exec mv {} {}.html --> find command perform this move(or)rename operation on the extracted filenames.

\; --> Represents the end of find command.