LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Howto move entire directories ? (https://www.linuxquestions.org/questions/linux-newbie-8/howto-move-entire-directories-533619/)

coolcargo 03-01-2007 11:06 AM

Howto move entire directories ?
 
Hello

My question may be trivial, but I'm really stuck.

How can I 'consolidate' several folders with each a partially identical structure, to one folder ?

For example

Given /test

With /test/A/ and /test/B/

And /test/A/a/b/c/ and /test/B/a/b/c/

Folders a,b,c have identical names but different content in A and B

How can I make that /test/a/b/c without loosing or overwriting any file?

Easy isn't it?

Thanks

Tinkster 03-01-2007 11:12 AM

Hi,

And this smacks of homework or assignment.

Hence a rather curt
Code:

man mv

Cheers,
Tink

khaleel5000 03-01-2007 02:18 PM

I was wondering the same question for a while , I have read man mv , haavent found any thing in thhis regard

PTrenholme 03-01-2007 02:36 PM

You should also look at man ls and man mount. One of the mount options lets you connect directories.

gregorian 03-02-2007 03:49 AM

I found that option in mount, but I got
Quote:

#mount --move A C

mount: wrong fs type, bad option, bad superblock on A,
or too many mounted file systems
I tried to move A to C. Something wrong?

Tinkster, you're not talking about mv -u A B right? It won't work. If you try mv -uf A/a B/ , it will say that you cannot overwrite.Well, I tried.

P.S. This has got something to do with basic commands, right? If it is advanced for a noob, tell me.

acid_kewpie 03-02-2007 03:54 AM

you don't want to go anywhere near mount. that's for moving filesystems not directories.

gregorian 03-02-2007 06:21 AM

PTrenholme suggested the usage of mount above. Can you tell me if I'm on the right track? Is it some subtle use of mv -u ? I know someone else asked this problem, but I'm equally eager to solve it.

P.S. Is this problem easy to solve?

acid_kewpie 03-02-2007 06:22 AM

no it's not. as detailed in the man pafge it's for moving mount points, not directories. e.g. move /dev/hda5's current mount point of /home to /oldhome

pk2001 03-02-2007 06:27 AM

Quote:

Originally Posted by coolcargo
Hello

My question may be trivial, but I'm really stuck.

How can I 'consolidate' several folders with each a partially identical structure, to one folder ?

For example

Given /test

With /test/A/ and /test/B/

And /test/A/a/b/c/ and /test/B/a/b/c/

Folders a,b,c have identical names but different content in A and B

How can I make that /test/a/b/c without loosing or overwriting any file?

Easy isn't it?

Thanks

Having read through your question a few times, I suspect it would be useful for you to phrase your question a little more precisely, possibly with an example.

gregorian 03-02-2007 06:33 AM

He's asking you how to merge two directories with identical structures.

Very simple example:

A/Music/ {song1.mp3,song2.mp3}
B/Music/ {song3.mp3}

Merged:

Music/{song1.mp3, song2.mp3, song3.mp3}

This is a simple example for files only. He wants to merge all the sub directories within the Music folder in such a way such that there is one directory tree having the same directory structure as A (or B; they're identical) and containing all the files in A and B.

pk2001 03-02-2007 07:19 AM

Quote:

Originally Posted by gregorian
He's asking you how to merge two directories with identical structures.

Very simple example:

A/Music/ {song1.mp3,song2.mp3}
B/Music/ {song3.mp3}

Merged:

Music/{song1.mp3, song2.mp3, song3.mp3}

This is a simple example for files only. He wants to merge all the sub directories within the Music folder in such a way such that there is one directory tree having the same directory structure as A (or B; they're identical) and containing all the files in A and B.

Aaaah, thank you Gregorian. I guess, if this were to be a one-off and not a frequently recurring operation, a simple work-around with "tar" would work.

Using Gregorian's example with the destination directory of "C"

cd A
tar cvf a.tar Music <enter>
cd ..
cd B
tar cvf b.tar Music <enter>
cd ..
cd C
mv B/b.tar ./b.tar
mv A/a.tar ./a.tar
tar xvf a.tar <enter>
tar xvf b.tar <enter>

With the "-k" option you can further prevent any undesired overwrites.

gregorian 03-02-2007 08:53 AM

Yep, it worked. Brilliant. How did you get such an idea, genius? I'm very impressed.

Edit:

Alternate:

Quote:

mv -rf A/* B/

Amenemhet 03-02-2007 02:06 PM

Quote:

Originally Posted by Tinkster
Hi,

And this smacks of homework or assignment.

Hence a rather curt
Code:

man mv

Cheers,
Tink

Haha, good spot that! Man is my most used word at the moment, all three letters on my laptop are disappearing fast!

I do however have sympathy. The man pages will be your best bet though, as you will end up understanding it better.

I have a question too, I am trying to back up all users home dirs as part of a script, and have want them to go to a specific file at a specific regular interval (will use logger for that) but I was wonderin... to pull ALL users stuff from their home dirs, would I just need to point tar to /home/ ? leaving it blank? This gives me a huge amount of info, way more than I think is necessary,but hey, I'm a noob too! Perhaps there is a variable I can use that will pull in what I want and not all that grey matter I dont know about. And also , if i use /home/ will this just be a dir listing? should I be using the find command and piping a variable through it with grep? I am getting a bit confused.....


edit: I had a similar operation for music files and alas I did it the hard way....
I copied everything to one folder, several commands, but I got rid of all me duplicates in the process :)

Tinkster 03-02-2007 02:53 PM

Quote:

Originally Posted by Amenemhet
I have a question too, I am trying to back up all users home dirs as part of a script, and have want them to go to a specific file at a specific regular interval (will use logger for that) but I was wonderin... to pull ALL users stuff from their home dirs, would I just need to point tar to /home/ ? leaving it blank? This gives me a huge amount of info, way more than I think is necessary,but hey, I'm a noob too! Perhaps there is a variable I can use that will pull in what I want and not all that grey matter I dont know about. And also , if i use /home/ will this just be a dir listing? should I be using the find command and piping a variable through it with grep? I am getting a bit confused.....

I'm not a 100% sure I follow. If you want ALL user stuff
I would expect it to be heaps.

Yes, "tar cf /big_disk/home.tar /home" will do what you want.
For subsequent runs you can use "tar uf /big_disk/home.tar /home".
To the best of my knowledge tar won't update compressed archives,
so if you want the archive compressed you'll have to do uncompressing
and compressing yourself before and after archiving.
e.g.
Code:

#!/bin/sh
gunzip /big_disk/home.tar.gz
tar uf /big_disk/home.tar /home
gzip /big_disk/home.tar

Of course that implies that the first run was done
manually all together, and that you manually compressed it.


Cheers,
Tink

P.S.: Glad you find man helpful - I use it a lot :}
You don't have to know everything, just know where and
how to find it ;}

Amenemhet 03-02-2007 03:28 PM

Thanks Tink, yes I need all the users stuff, so, will this do? Or is it just an ls of their home?
Also, how can I prevent people from logging on temporarily? Is there a way to use the nologin command and give it a time variable for say , while the backup is actually running?
ie:
nologin
tar -cvf /var/local/backup/homedir-$(date +%a-%b-%d).tar /home
login
This doesnt seem correct, and the man pages for no login are sparse, is there another command I could use?


All times are GMT -5. The time now is 03:43 PM.