0

I have a directory full of files name: "file1.mp4.mp4 file1.mp4.mp4 file1.mp4.mp4 ...".

I would like to rename all of them using find from "file1.mp4.mp4" to "file1.mp4" and some other bash tools it would look something like this but with a regular expression:

find . -name "*.mp4" |xargs echo -0

dogbane
  • 266,786
  • 75
  • 396
  • 414
fenec
  • 5,637
  • 10
  • 56
  • 82

5 Answers5

2

Use rename. If all the files are in the same directory, you can do this:

rename 's/\.mp4.mp4$/.mp4/' *.mp4.mp4

Otherwise you might want something like:

rename 's/\.mp4.mp4$/.mp4/' `find . -name "*.mp4.mp4"`

Also, to see what would happen when you run rename, just to debug the statement, do this:

rename --no-act 's/\.mp4.mp4$/.mp4/' *.mp4.mp4

This even works if the filename contains a space, for example:

$ touch foo.mp4.mp4
$ touch "bar baz.mp4.mp4"
$ ls
bar baz.mp4.mp4  foo.mp4.mp4
$ rename  's/\.mp4.mp4$/.mp4/' *.mp4.mp4
$ ls
bar baz.mp4  foo.mp4
$ 
snim2
  • 4,004
  • 27
  • 44
2

Or try this simple bash command in a loop?

mv /path/to/file.{mp4.mp4, mp4}
Will
  • 481
  • 3
  • 11
1

Try something like this -

for file in /path/to/dir/*.mp4; do 
    mv "$file" "${file%.*}"; 
done
jaypal singh
  • 74,723
  • 23
  • 102
  • 147
0

Do you have the rename command? If so, you can try:

rename .mp4 "" *.mp4.mp4

This will remove the final .mp4 suffix from all files with extension .mp4.mp4 in the current directory.

dogbane
  • 266,786
  • 75
  • 396
  • 414
0
find . -name '*.mp4.mp4' -exec echo mv {} \`dirname {}/\`/\`basename {} .mp4\` \; > mp4.sh && ./mp4.sh && rm mp4.sh
Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92