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.

I may be going bonkers here, but I'm trying to move a directory to a new location, overwriting the contents (on Linux, using bash).

Everytime I try it, it responds with "mv: cannot move `./src' to a subdirectory of itself"

eg. I have:

/src
/new/dir/src
/$ mv src/ new/dir/

If I delete the destination dir, then it works. I know I can move the contents of the source dir to overwrite the destination, but I'd like to use the same command to overwrite the destination if it already exists, or move the source if it doesn't.

share|improve this question
    
weird, your example works for me... –  David Z May 12 '10 at 19:04
1  
a thought: are there any symlinks involved? –  David Z May 12 '10 at 19:06
    
Looks okay to me too... –  Kyle Brandt May 12 '10 at 19:14
    
yes there is, the 'root' dir is symlinked so it appears elsewhere in th filesystem (not a subdir) but .... I'll investigate that tomorrow. –  gbjbaanb May 12 '10 at 21:17

1 Answer 1

try providing the absolute path to each directory.

i.e. mv /src /new/dir/

also, you can look into rsync to copy files and delete existing files, and all that.

you can also do something like:

#!/bin/sh
if [ -e /new/dir/src/ ]; then
  rm -rf /new/dir/src/
fi
mv /src /new/dir/

unless you're concerned with keeping files in /new/dir/src/, in which case rsync would be a better option.

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.