LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-01-2007, 11:06 AM   #1
coolcargo
LQ Newbie
 
Registered: Mar 2007
Posts: 1

Rep: Reputation: 0
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
 
Old 03-01-2007, 11:12 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hi,

And this smacks of homework or assignment.

Hence a rather curt
Code:
man mv

Cheers,
Tink
 
Old 03-01-2007, 02:18 PM   #3
khaleel5000
Member
 
Registered: Oct 2005
Location: Pakistan
Distribution: Debian,Pclinuxos
Posts: 327

Rep: Reputation: 31
I was wondering the same question for a while , I have read man mv , haavent found any thing in thhis regard
 
Old 03-01-2007, 02:36 PM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
You should also look at man ls and man mount. One of the mount options lets you connect directories.
 
Old 03-02-2007, 03:49 AM   #5
gregorian
Member
 
Registered: Apr 2006
Posts: 509

Rep: Reputation: 34
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.

Last edited by gregorian; 03-02-2007 at 03:53 AM.
 
Old 03-02-2007, 03:54 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
you don't want to go anywhere near mount. that's for moving filesystems not directories.
 
Old 03-02-2007, 06:21 AM   #7
gregorian
Member
 
Registered: Apr 2006
Posts: 509

Rep: Reputation: 34
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?
 
Old 03-02-2007, 06:22 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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
 
Old 03-02-2007, 06:27 AM   #9
pk2001
LQ Newbie
 
Registered: Feb 2007
Location: Singapore
Distribution: Debian Sarge/Etch
Posts: 19

Rep: Reputation: 0
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.
 
Old 03-02-2007, 06:33 AM   #10
gregorian
Member
 
Registered: Apr 2006
Posts: 509

Rep: Reputation: 34
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.

Last edited by gregorian; 03-02-2007 at 06:42 AM.
 
Old 03-02-2007, 07:19 AM   #11
pk2001
LQ Newbie
 
Registered: Feb 2007
Location: Singapore
Distribution: Debian Sarge/Etch
Posts: 19

Rep: Reputation: 0
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.
 
Old 03-02-2007, 08:53 AM   #12
gregorian
Member
 
Registered: Apr 2006
Posts: 509

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

Edit:

Alternate:

Quote:
mv -rf A/* B/

Last edited by gregorian; 03-02-2007 at 09:54 AM.
 
Old 03-02-2007, 02:06 PM   #13
Amenemhet
LQ Newbie
 
Registered: Mar 2007
Location: canada
Distribution: fedora core 5, ubuntu 6.1
Posts: 13

Rep: Reputation: 0
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

Last edited by Amenemhet; 03-02-2007 at 02:13 PM.
 
Old 03-02-2007, 02:53 PM   #14
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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 ;}
 
Old 03-02-2007, 03:28 PM   #15
Amenemhet
LQ Newbie
 
Registered: Mar 2007
Location: canada
Distribution: fedora core 5, ubuntu 6.1
Posts: 13

Rep: Reputation: 0
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?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
useing SCP to copy entire directories with sub folders? Lleb_KCir Linux - General 5 09-13-2005 09:08 PM
xmms en que entire directories oily_rags Linux - Software 2 09-14-2004 01:50 PM
Move certain files into different directories facets Programming 6 05-28-2004 01:20 PM
partitioning a new drive, which directories can I move ? xucaen Linux - General 2 02-25-2004 09:03 PM
Can I move Untarred directories? Nigel_Tufnel Linux - General 5 08-08-2002 08:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration