I am receiving an error when trying to mv some files that really doesn't make sense. I receive this error:

mv: cannot move `thatDir' to a subdirectory of itself, `/usr/local/apache-tomcat-6.0.32/webapps/thatDir'

When running the following command to replace an already existing thatDir in /webapps:

From /home/myUser/war_files/ 
mv thatDir /usr/local/apache-tomcat-6.0.32/webapps

I have also tried everything up to:

sudo mv /home/myUser/war_files/thatDir /usr/local/apache-tomcat-6.0.32/webapps

With no luck. I have the necessary permissions to do this (plus I'm using sudo) and still nothing. This exact same operation has been carried out before by someone else at my office (who is no longer working here).

I've tried googling around and even have seen another question on serverfault but everyone says the same this as the comment on that issue: "perhaps there are symlinks involved and you don't know about it."

That is not the issue. I tried viewing the directories with readlink -e (as the comment in the other ticket suggests) but there are no symlinks involved.

Any help would be appreciated.

Link to the other question related to this: Cannot move folder to a subdirectoy of itself - What's going on?

As mentioned in my comment response below, here are steps to reproduce this issue. As you will be able to see, links could not be responsible for this (also, I am using bash unix):

mkdir /home/myUser/testOuter    
cd /home/myUser/testOuter
mkdir test1
cd test1
mkdir moveMe
cd moveMe
touch testfile1.txt
cd ../..
mkdir test2
cd test2
mkdir moveMe
cd moveMe
touch testfile2.txt
cd ../../test1
mv moveMe ../test2

And then I get the error output:

mv: cannot move `moveMe' to a subdirectory of itself, `../test2/moveMe'

but it is clearly not in a subdirectory of itself, nor are there any links involved.

It works if I remove the files from test2/moveMe/ but that is unacceptable as I need to overwrite all files that are in test1 with test2, preserve existing files in test1 that do not exist in test2 (such as user generated content), and move in any files from test2 that do not already exist in test1. (ie. a regular, every day type of move operation).

  • 1
    Did you check for a hard link? – jdigital Nov 28 '12 at 23:52
  • 1
    In case you're on Linux specifically rather than generic unix, rather than hard links Linux uses mount --bind, check the output of mount | grep bind – DerfK Nov 28 '12 at 23:59
  • There isn't a hard link involved, nor does mount | grep bind produce any output.. I can reproduce this too. I've added the reproducible steps to the original ticket. Perhaps they may shed some light? – Inversus Nov 29 '12 at 0:33

Actually, reading what you're trying to do, you're probably hitting this bug where someone pointed out that you get an incorrect error message when you try to overwrite a non-empty directory with another directory (which is not allowed).

| improve this answer | |
  • Yes. That's exactly what is going on. How do I move directory A into B as described at the end of my edit? sorry, this is probably a n00b question. It's been years since I took unix in school.. – Inversus Nov 29 '12 at 0:32
  • Found it. It's so simple it's painful once you mentioned that I cannot do this with mv.. cp -R /path/to/bar/* /path/to/foo – Inversus Nov 29 '12 at 0:38

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.