Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:



share|improve this question
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
Crossposted on StackOverflow, then mod-moved to SuperUser (please don't crosspost). – Dennis Williamson Jul 20 '10 at 1:22
up vote 2 down vote accepted

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.

share|improve this answer
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
Directory structure added... Thanks :-) – Eric Jul 20 '10 at 1:36
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

This should work:

mv -f ./tmp/members .
share|improve this answer
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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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