How to use »find« on macOS to get files NOT containing a specific filename extension
In our case we have had a couple of videos we created and some of them were accidentially saved without a filename extension. Most files has been saved with the
*.mov
*.mp4
extensions. To get all files that have been saved without any extension we used the find-command in terminal to get all the names. The command was
find . -type f -not -name "*.mov" -not -name "*.mp4"
The parameter »-type f« searched for files only and the negeation »-not -name« excluded all files with a specific extension. We needed to exclude only two types of filename extensions so the command is pretty simple.
After that we wanted to rename all those files to add the filename extension »*.mp4«. We used the command
find . -type f -not -name "*.mov" -not name "*.mp4" -exec mv {} ./{}.mp4 \;
With the parameter -exec we executed the mv (move) command for each file. The first brace »{}« takes the filename that the command returns and the second one »./{}.mp4« moves the file with the existing filename and adds the extension ».mp4«. The backslash escapes the semicolon which ends the command. If you forget to escape the semicolon the command would not be executed because the commands expects additional commands or parameters. So don't forget to escape the semicolon.
I Hope that helps!