mv: cannot overwrite directory with non-directory

anarchist picture anarchist · Dec 20, 2013 · Viewed 37.1k times · Source

Is it possible to get around this problem?

I have a situation where I need to move some files to 1 directory below.

/a/b/c/d/e/f/g

problem is that the filename inside g/ directory is the same as the directory name

and I receive the following error:

mv: cannot overwrite directory `../297534' with non-directory

Example: /home/user/data/doc/version/3766/297534 is a directory, inside there is a also a file named 297534

so I need to move this file to be inside /home/user/data/doc/version/3766

Command This is what I am running: (in a for loop)

cd /home/user/data/doc/version/3766/297534
mv * ../

Answer

lreeder picture lreeder · Dec 20, 2013

You can't force mv to overwrite a directory with a file with the same name. You'll need to remove that file before you use your mv command.