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 |
Hi,
And this smacks of homework or assignment. Hence a rather curt Code:
man mv Cheers, Tink |
I was wondering the same question for a while , I have read man mv , haavent found any thing in thhis regard
|
You should also look at man ls and man mount. One of the mount options lets you connect directories.
|
I found that option in mount, but I got
Quote:
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. |
you don't want to go anywhere near mount. that's for moving filesystems not directories.
|
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? |
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
|
Quote:
|
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. |
Quote:
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. |
Yep, it worked. Brilliant. How did you get such an idea, genius? I'm very impressed.
Edit: Alternate: Quote:
|
Quote:
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 :) |
Quote:
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 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 ;} |
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. |