Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-21-2009, 08:54 AM   #1
Registered: Mar 2009
Posts: 82

Rep: Reputation: 16
Combine 10,000 small files into a big one

I got around 10,000 files inside a folder, each of them contains around 20-30 lines.

Is there some quick way (probably bash command) to combine them into a big one ?


This number of files cause 'cat *' to fail and it reminds me 'argument list too long'.

A Perl program is working on combing it anyway, but just a little bit slow to me.
Old 10-21-2009, 09:08 AM   #2
Registered: Sep 2005
Location: London, UK
Distribution: Debian
Posts: 258

Rep: Reputation: 38
This sort of thing?
for i in `ls -1`; do
    cat $i >> newfile.txt
EDIT: If the perl script is slow, I can't see the above being any quicker.

*gets more coffee*

Last edited by Lordandmaker; 10-21-2009 at 09:09 AM. Reason: noticed the OP's last line.
Old 10-21-2009, 09:16 AM   #3
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,937
Blog Entries: 14

Rep: Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160
Assuming they're all in a single directory and there is nothing else there.
cd <directory>
find . -maxdepth 1 |grep -v <outputfile> |xargs cat >> <outputfile>

Of course you'd want to make sure where ever your outputfile is has enough space free to contain all your files output.


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
howto combine pdf files JUbuntu Linux - Newbie 2 04-29-2008 08:15 PM
combine shadow files packets Linux - Newbie 2 04-18-2008 05:14 AM
LXer: SugarCRM Announces 1,000 Customers and 1,000,000 Open Source Downloads as Momentum for Open Source Applications Grows LXer Syndicated Linux News 0 12-19-2006 05:33 AM
1,000,000,000 PCs by 2010 masand Linux - News 4 11-01-2004 01:55 AM
Best way to combine files? JockVSJock Programming 4 04-25-2004 07:38 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:15 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration