Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to move all content of directories to another one?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
SnEptUne
l33t
l33t


Joined: 23 Aug 2004
Posts: 656

PostPosted: Thu Nov 25, 2004 7:47 am    Post subject: How to move all content of directories to another one? Reply with quote

Hi,

Does anyone know how to move the content of a directory to another directory which contains similar content. For example, I have two directories dir1 and dir2 and their content is as follows:

Code:
dir1/
   base/
      ...
   docs/
      ...
   exec/
      ...

dir2/
   base/
      ...
   docs/
      ...
   exec/
      ...


Where "..." denotes files. Iniuitively, I would execute
Code:
mv -f dir1/* dir2/

However, I would receive this error:
mv: cannot overwrite directory `dir2/base`
mv: cannot overwrite directory `dir2/docs`
mv: cannot overwrite directory `dir2/exec`

cp and rm is not an option due to a very limited disk space.

In the other word, how can I merge two directory with only mv command on a diskspace critical environment?[/code]
_________________
"There will be more joy in heaven over the tear-bathed face of a repentant sinner than over the white robes of a hundred just men." (LM, 114)
Back to top
View user's profile Send private message
BWoso
l33t
l33t


Joined: 31 Dec 2003
Posts: 920
Location: Cleveland Ohio, USA

PostPosted: Thu Nov 25, 2004 8:42 am    Post subject: Reply with quote

If you are planning on copying over the files/folders in dir2 why don't you just rm -frv dir2/* And if you are not planning on copying over them just rename the files/folders in dir1 so they are not the same as in dir2?
_________________
I think that the forums are the greatest thing about Gentoo, thanks to everyone that posts on them!

The best way to cheer yourself up is to try to cheer somebody else up.
-Mark Twain-
Back to top
View user's profile Send private message
BlackEdder
Advocate
Advocate


Joined: 26 Apr 2004
Posts: 2588
Location: Dutch enclave in Egham, UK

PostPosted: Thu Nov 25, 2004 9:47 am    Post subject: Reply with quote

Quote:
mv: cannot overwrite directory `dir2/base`
mv: cannot overwrite directory `dir2/docs`
mv: cannot overwrite directory `dir2/exec`

AFAIK it should still have copied the files into the new directory.
Back to top
View user's profile Send private message
SnEptUne
l33t
l33t


Joined: 23 Aug 2004
Posts: 656

PostPosted: Thu Nov 25, 2004 10:01 am    Post subject: Reply with quote

Unfortunately, there isn't just 3 directory. There are over 12 directories and each directories have subfolder. I can't rm -fr dir2/* because there are some files in dir2/* that dir1/ does not have and vice-versa. It doesn't have to be a command, I am thinking of a script. However, I am terrible at writting shell script. Does anyone have any idea?
_________________
"There will be more joy in heaven over the tear-bathed face of a repentant sinner than over the white robes of a hundred just men." (LM, 114)
Back to top
View user's profile Send private message
tomk
Bodhisattva
Bodhisattva


Joined: 23 Sep 2003
Posts: 7221
Location: Sat in front of my computer

PostPosted: Thu Nov 25, 2004 2:14 pm    Post subject: Reply with quote

Maybe this is a job for rsync?
_________________
Search | Read | Answer | Report | Strip
Back to top
View user's profile Send private message
SnEptUne
l33t
l33t


Joined: 23 Aug 2004
Posts: 656

PostPosted: Fri Nov 26, 2004 12:23 am    Post subject: Reply with quote

Rsync would just sync two directories instead of merging them. The end result would be two set of directories with the same content, which is not feasible for a disk space limited partition.
_________________
"There will be more joy in heaven over the tear-bathed face of a repentant sinner than over the white robes of a hundred just men." (LM, 114)
Back to top
View user's profile Send private message
Jake
Veteran
Veteran


Joined: 31 Jul 2003
Posts: 1132

PostPosted: Fri Nov 26, 2004 3:48 am    Post subject: Reply with quote

Code:
cd dir1
for i in `find . -mindepth 2 -maxdepth 2` ; do mv $i ../dir2/$i ; done

The for loop probably won't like spaces or some other characters, so it's not a perfect solution.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum