0

I have several movies in a folder.

For example:

~/Downloads/Movies/Movie A (1998).mkv  
~/Downloads/Movies/Movie B (1999).mkv  
~/Downloads/Movies/Movie C (2000).mkv

I would like to put each file into its own folder, and name the folder identical to the file name. I have many files, so I would like to be able to do this in a batch if possible.

For example:

~/Downloads/Movies/Movie A (1998)/Movie A (1998).mkv
~/Downloads/Movies/Movie B (1999)/Movie B (1999).mkv
~/Downloads/Movies/Movie C (2000)/Movie C (2000).mkv

I have tried to use the bash command on this page

find . -name "*.mkv" -exec sh -c 'mkdir "${1%.*}" ; mv "" "${1%.*}" ' _ {} \;

However, I get the error message:

mv: cannot stat '': No such file or directory

The folder is created correctly, but the command fails to move the file into the folder, and I get the above error.

Which part of

; mv "" "${1%.*}" ' _ {} \;

is incorrect, and how so?

Also, if there are other commands or scripts you think would do the job, that would be appreciated.

5

"" should be "$1". That argument of mv should be the file to be moved, and obviously it can't be left empty.

  • @MartinJS Glad you found a solution! Please click the checkmark below the vote arrows. This will "accept" the answer, and it effectively marks your question as "resolved". – wjandrea Nov 3 '18 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.