Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-02-2005, 08:30 AM   #1
LQ Newbie
Registered: Aug 2004
Location: Washingtonville, NY USA
Distribution: RH9
Posts: 5

Rep: Reputation: 0
merge two folders

Hi there,
I need to merge the contents of two folders. Each folder contains about 650 files, with duplicate names.

I was thinking my scritp should look somehting like this:

cd /dir1  #source
for name in `ls`

cat $name >> /dir2/$name
What do you think?
Old 05-02-2005, 08:38 AM   #2
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
I think that logic's right - but I'd advise you test it with non-critical data first.

It looks as though you might have a few syntax errors though - try something like this:


cd /dir1
for name in `ls`; do
    cat $name >> /dir2/$name
Also bear in mind this won't get any files whose names begin with a dot, and that interesting things could happen if dir1 contains any subdirectories.

Last edited by trevelluk; 05-02-2005 at 08:41 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
merge directories d-fens Linux - General 9 02-04-2010 05:48 PM
merge partitions? Leonig Mig Linux - General 2 06-06-2005 11:15 AM
Merge JPGs mddolloff Linux - Software 5 11-21-2004 07:41 AM
merge mailboxes illtbagu Linux - Software 0 03-13-2004 01:53 PM
Merge 2 arrays in C linux_GNUbie Programming 6 12-11-2003 05:28 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:34 AM.

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