LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 05-02-2005, 08:30 AM   #1
TechNett
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:

Code:
#!/bin/bash
cd /dir1  #source
for name in `ls`
do

cat $name >> /dir2/$name
What do you think?
Thanks,
Nett
 
Old 05-02-2005, 08:38 AM   #2
trevelluk
Member
 
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:

Code:
#!/bin/bash

cd /dir1
for name in `ls`; do
    cat $name >> /dir2/$name
done
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.
 
  


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:34 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