LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   merge contents of folders (https://www.linuxquestions.org/questions/linux-newbie-8/merge-contents-of-folders-556379/)

minimole 05-24-2007 10:19 AM

merge contents of folders
 
Hi,

I have alot of different folders with alot of files inside of them my question is, is there a way I can take the contents of these folders and merge them into one folder? other wise i have to go through them one by one and it is gonna take a long long time there are about 150 folders and probably about 15000 items inside of them. i have tried a few things but but none seem to work.

Thank you in advance

bsdunix 05-24-2007 10:44 AM

You can use the mv command. Just be careful to not overwrite an existing file/folder.

Examples are here:

http://www.linuxcommand.org/lts0050.php

http://members.toast.net/art.ross/Li.../command3.html

Basically to move one directory/folder/file to another (bold italics is example output listing):
Code:

$ ls
dir1 dir2 dir
$ mv dir1 dir
$ ls
dir2 dir
$ cd dir
$ ls
dir1

or
Code:

$ ls
file1 dir
$ mv file1 dir
$ ls
dir
$ cd dir
$ ls
file1


pixellany 05-24-2007 11:08 AM

Depending on the complexity of the hierarchy, you may need a script.

For example, suppose DIR_1 has a bunch of files that you want to move to DIR_2:

in DIR_1, "mv * DIR_2" will move everything---but it will also move any directories. (That may be OK in your case)

minimole 05-24-2007 05:59 PM

It is pretty messy. Been trying to write a script but i cant think of a way to do it. the way that have been show is the way i had been doing it and it was taking forever.

It matters not now, I have done it and it took a while lol.
Thank you anyway.

SciYro 05-25-2007 04:32 AM

cd /path/to/base/dir

Code:

find ./ -type f
if that list of files is correct for what you want, then proceed to next command:

Code:

find ./ -type f | xargs mv --target-directory /path/to/some/storage/dir
That should do it, tho, sorry you had to do it by hand..

minimole 05-25-2007 05:46 AM

Thank you i will keep that for future reference. No need to be sorry it wasnt so bad and it encourages me to learn more.

Thank you


All times are GMT -5. The time now is 01:21 AM.