Skip to main content
added example and alternate solution
Source Link
Sundeep
  • 12.2k
  • 3
  • 28
  • 75

Try this:

find -type f -not -name '*.mp4' -exec rename -n 's/$/.mp4/' {} + 

This checks for all files in current directory and its sub-folders that do not end with .mp4 and renames them to add the extension

Assumes perl based rename command, -n option is to show how the files will be renamed. Once you are okay with it, remove the option and run the command again


**Example:**
$ find -type f ./rand_numbers.txt ./tst ./abc/123 ./abc/zyx.txt $ find -type f -not -name '*.mp4' -exec rename -n 's/$/.mp4/' {} + rename(./rand_numbers.txt, ./rand_numbers.txt.mp4) rename(./tst, ./tst.mp4) rename(./abc/123, ./abc/123.mp4) rename(./abc/zyx.txt, ./abc/zyx.txt.mp4) 

If you define file not having extension to mean file names without . in their name, use:

$ find -type f -not -name '*.*' -exec rename -n 's/$/.mp4/' {} + rename(./tst, ./tst.mp4) rename(./abc/123, ./abc/123.mp4) 

Try this:

find -type f -not -name '*.mp4' -exec rename -n 's/$/.mp4/' {} + 

This checks for all files in current directory and its sub-folders that do not end with .mp4 and renames them to add the extension

Assumes perl based rename command, -n option is to show how the files will be renamed. Once you are okay with it, remove the option and run the command again

Try this:

find -type f -not -name '*.mp4' -exec rename -n 's/$/.mp4/' {} + 

This checks for all files in current directory and its sub-folders that do not end with .mp4 and renames them to add the extension

Assumes perl based rename command, -n option is to show how the files will be renamed. Once you are okay with it, remove the option and run the command again


**Example:**
$ find -type f ./rand_numbers.txt ./tst ./abc/123 ./abc/zyx.txt $ find -type f -not -name '*.mp4' -exec rename -n 's/$/.mp4/' {} + rename(./rand_numbers.txt, ./rand_numbers.txt.mp4) rename(./tst, ./tst.mp4) rename(./abc/123, ./abc/123.mp4) rename(./abc/zyx.txt, ./abc/zyx.txt.mp4) 

If you define file not having extension to mean file names without . in their name, use:

$ find -type f -not -name '*.*' -exec rename -n 's/$/.mp4/' {} + rename(./tst, ./tst.mp4) rename(./abc/123, ./abc/123.mp4) 
Source Link
Sundeep
  • 12.2k
  • 3
  • 28
  • 75

Try this:

find -type f -not -name '*.mp4' -exec rename -n 's/$/.mp4/' {} + 

This checks for all files in current directory and its sub-folders that do not end with .mp4 and renames them to add the extension

Assumes perl based rename command, -n option is to show how the files will be renamed. Once you are okay with it, remove the option and run the command again