"mv: cannot stat file" in for loop

Posted by F.C. on Super User See other posts from Super User or by F.C.
Published on 2012-11-05T04:34:49Z Indexed on 2012/11/05 5:04 UTC
Read the original article Hit count: 458

Filed under:
|
|
|
|

I wanted to rename a lot of files with a pattern so I tried this for loop:

$ for f in *; do mv \""$f"\" \""HouseMD-S06E${f#*Episode }"\"; done

But I got this error:

mv: cannot stat `"House MD Season 6 Episode 01 - Broken (Parts 1 & 2).avi"': No such file or directory

So what I did was echo the mv commands to a file like this:

$ for f in *; do echo mv \""$f"\" \""HouseMD-S06E${f#*Episode }"\">>mv.txt; done

And the run the file with source.

Any ideas why the first for didn't work and how can I fix it?

© Super User or respective owner

Related posts about linux

Related posts about bash