View previous topic :: View next topic |
Author |
Message |
SnEptUne l33t


Joined: 23 Aug 2004 Posts: 656
|
Posted: Thu Nov 25, 2004 7:47 am Post subject: How to move all content of directories to another one? |
|
|
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
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 |
|
 |
BWoso l33t


Joined: 31 Dec 2003 Posts: 920 Location: Cleveland Ohio, USA
|
Posted: Thu Nov 25, 2004 8:42 am Post subject: |
|
|
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 |
|
 |
BlackEdder Advocate


Joined: 26 Apr 2004 Posts: 2588 Location: Dutch enclave in Egham, UK
|
Posted: Thu Nov 25, 2004 9:47 am Post subject: |
|
|
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 |
|
 |
SnEptUne l33t


Joined: 23 Aug 2004 Posts: 656
|
Posted: Thu Nov 25, 2004 10:01 am Post subject: |
|
|
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 |
|
 |
tomk Bodhisattva


Joined: 23 Sep 2003 Posts: 7221 Location: Sat in front of my computer
|
|
Back to top |
|
 |
SnEptUne l33t


Joined: 23 Aug 2004 Posts: 656
|
Posted: Fri Nov 26, 2004 12:23 am Post subject: |
|
|
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 |
|
 |
Jake Veteran

Joined: 31 Jul 2003 Posts: 1132
|
Posted: Fri Nov 26, 2004 3:48 am Post subject: |
|
|
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 |
|
 |
|