Originally Posted by
Applenazi
... Willing to take a crack at this? I am trying to rename a large amount of files. Each file is located in its own separate directory. The command I used was as follows:
Code:
find -type f -name '*.mp4' | rename -f 's/.*/clip.mp4/'
The problem is that instead of renaming, it simply deletes
, not ideal.
Without the -f param I get the following output:
In the instances with the random file name such as in directory 00740 a file named clip.mp4 does NOT exist in that directory, so I assume its problem is that file clip.mp4 DOES exist somewhere within the top level directory overall... Any assistance would be very much appreciated, thanks!
You are renaming all files to clip.mp4 in your current directory, i.e all renames overwrite the same file over and over again, like this:
rename ./a/a.mp4 -> clip4.mp4
rename ./b/b.mp4 -> clip4.mp4 <- overwrites the previously created clip4.mp4 (and removes the source since this is a rename)
The end result of this (forced) rename is obviously one file named clip4.mp4 with the contents of the last file renamed and all other files effectively deleted.
You need to include the directory path in your rename operation like this:
Code:
find -type f -name "*.mp4" | rename 's/(.*)\/.*/$1\/clip.mp4/'
The (.*)\/ will match the path until the last / as expression $1 and then replace the remaining file name with clip4.mp4
Note that if you have 2 files in the same directory they will still overwrite each other.
If you add the -n option to the rename command it should show you what it would do.