Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:
./
./members
./members/srno
./members/srno/expired
./members/1
./members/1/active
./members/members
./members/members/srno
./members/members/srno/expired
./members/members/1
./members/members/1/active
./members/members/57364
./members/members/57364/expired
./members/members/11939
./members/members/11939/expired
./members/members/123
./members/members/123/expired
./members/members/73331
./members/members/73331/expired
./members/members/88144
./members/members/88144/expired
./members/members/25051
./members/members/25051/expired
./members/57364
./members/57364/expired
./members/11939
./members/11939/expired
./members/123
./members/123/expired
./members/73331
./members/73331/expired
./members/88144
./members/88144/expired
./members/remove
./members/25051
./members/25051/expired
./index.html
./tmp
./tmp/members
./tmp/members/srno
./tmp/members/srno/expired
./tmp/members/1
./tmp/members/1/active
./tmp/members/57364
./tmp/members/57364/expired
./tmp/members/11939
./tmp/members/11939/expired
./tmp/members/123
./tmp/members/123/expired
./tmp/members/73331
./tmp/members/73331/expired
./tmp/members/88144
./tmp/members/88144/expired
./tmp/members/25051
./tmp/members/25051/expired
./tmp/subscribers.xml
./premium.cgi

Thanks!

-Eric

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
1  
Crossposted on StackOverflow, then mod-moved to SuperUser (please don't crosspost). –  Dennis Williamson Jul 20 '10 at 1:22

3 Answers 3

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

 
discard

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.