Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In FreeBSD (I suppose it works like Linux et al in this regard), I'd like to move src_parent/mydir to dst_parent/mydir. dst_parent/mydir already exists, and it contains some subdirs that's also contained by src_parent/mydir. We can assume that no file exists in both src and dst.

Edit: The source- and destination-directories are on different filesystems.


Example:

src_parent/dir:

subdir1/
  file1b
subdir2/
  file2b

dst_parent/dir:

subdir1/
  file1a
subdir2/
  file2c

I'd like to mv src_parent/dir dst_parent/dir, so that dst_parent/dir ends up like this:

subdir1/
  file1a
  file1b
subdir2/
  file2b
  file2c

, which is the two dirs merged together. This is approx. the same behaviour as when moving files with GUI in f.x. MS Windows.


Already tried:

I've unsuccessfully tried this:

$ mv -f /src_parent/mydir/* /dst_parent/mydir/*
mv: rename /src_parent/mydir/subdir1 to /dst_parent/mydir/subdir1: Directory not empty
share|improve this question

1 Answer 1

up vote 2 down vote accepted

I'd link the files first and then remove the source dir:

 cd /src_parent
 find mydir -depth | cpio -pdlmv /dst_parent

check /dst_parent/mydir - if everything is fine:

 rm -rf /src_parent/mydir
share|improve this answer
1  
Ah - if /src_parent and /dst_parent are on different filesystems, omit the cpio-option 'l' –  ktf Oct 13 '11 at 15:53
    
I've never heard of cpio before. When should I use that instead of cp (when not working with archives) (I looked briefly in the manpages). –  poplitea Oct 13 '11 at 15:59
1  
Other alternative: link the files with pax -r -w -l instead of cpio to the destination directory (assuming source and destination are on the same filesystem. Pleayse consult the man-page of pax for syntax details –  guenter Oct 13 '11 at 16:44

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.