0

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

Eric
  • 160
  • 8

3 Answers3

2

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.

Warner
  • 23,440
  • 2
  • 57
  • 69
  • 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 01:00
  • Thanks, that is working, but still leaves behind the old directories. Best, -Eric – Eric Jul 20 '10 at 01:46
  • `rm -rf` the old data that you don't want. – Warner Jul 20 '10 at 01: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 01: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 01:56
0

This should work:

mv -f ./tmp/members .
Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148
0

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.

Slartibartfast
  • 3,265
  • 17
  • 16