can anyone tell me why when I type:

mv -f ./tmp/members ./

I get:

mv: cannot move `./tmp/members' to a subdirectory of itself, `./members'

And moreover the correct way to move this directory?

Also, there is already a directory at ./members ... I want to completely overwrite this directory, not just add the new contents to it.

Directory Structure:



  • Is there symlinks involved? – Weboide Jul 20 '10 at 1:03
  • nope, no symlinks – Eric Jul 20 '10 at 1:04
  • ok, I lied... the folder above the folder I'm working in has a symlink pointing to it... but there are no symlinks in the folder I'm moving. – Eric Jul 20 '10 at 1:20
  • 1
    Crossposted on StackOverflow, then mod-moved to SuperUser (please don't crosspost). – Dennis Williamson Jul 20 '10 at 1:22

Try the following:

cp -rf ./tmp/members/* ./

Following that, remove ./tmp/members if you don't want to keep a copy. mv doesn't "overwrite."

Using relative paths is a bad habit and will be something that you will easily regret. I recommend using full paths whenever reasonable.

  • Thanks, but this leaves behind the old contents of ./members as well I'm trying to do a near-instantaneous replace, as files are being served by apache from this directory. Thanks, -Eric – Eric Jul 20 '10 at 1:00
  • Thanks, that is working, but still leaves behind the old directories. Best, -Eric – Eric Jul 20 '10 at 1:46
  • rm -rf the old data that you don't want. – Warner Jul 20 '10 at 1:46
  • Thanks, though that would require doing a recursive comparison between the 2... I think my best option might be to use rsync, as it seems that mv and cp don't support this. – Eric Jul 20 '10 at 1:51
  • cp -rf will copy everything. rsync's probably the better choice, I considered suggesting it but was stuck on the method. – Warner Jul 20 '10 at 1:56

This should work:

mv -f ./tmp/members .
  • nope, that returns the same error, but thanks for trying :-) – Eric Jul 20 '10 at 1:14
  • I've discovered that this works: mv tmp/members members but only for new contents... the old contents are still left behind... – Eric Jul 20 '10 at 1:29
  • That just moves the directory within the subdirectory. – Warner Jul 20 '10 at 1:32
  • @Warner: That's what I thought he wanted. The question was apparently incomplete. – Dennis Williamson Jul 20 '10 at 2:44
  • Yea, I was responding to Eric's comment. I suspected you were acting in good faith, Dennis. – Warner Jul 20 '10 at 3:14

Another answer (though you already accepted another):

mv ./members ./.trash-members ; mv ./tmp/members ./ ; rm -rf ./.trash-members &

This way the old directory is removed in the background, and the new directory is put into place in very short order (the two moves should be very quick as long as you're on the same filesystem)

Also note that this solution does not use secure temporary files the way it should.

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.