Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have lots of files eg.

b.yyy.001 b.yyy.002 b.yyy.003

How can I merge then into: and b.yyy? In Ubuntu

share|improve this question

Assuming the original file was straightforwardly split into chunks (so the chunks don't have headers or anything like that), use the concatenate command:

cat >

Make sure that you have all the pieces, since cat will just concatenate what it's given. If your shell is bash (the default shell) or zsh, you can use

cat{001..002} >
cat b.yyy.{001..003} >b.yyy

This way, cat is given the names of the expected pieces in order, so you will get an error message if any of the pieces is missing.

share|improve this answer
Assuming that the current working directory contains only those pieces, he can also use cat* > cat – Cristian Ciupitu Sep 18 '10 at 12:45
@Cristian: I didn't use * because it's more failure-prone. If the pieces are called …,,, …, it's obvious that .??? won't work, whereas .* would silently concatenate the pieces in the wrong order. .??? is also a little more robust against stray files being caught, though .[0-9][0-9][0-9] would be safer (but would require significantly more typing). – Gilles Sep 18 '10 at 13:48
@Giles: a good split program would use proper file names for the pieces to avoid this issue. – Cristian Ciupitu Sep 18 '10 at 20:01
$ cat >
$ cat b.yyy.001 b.yyy.002 b.yyy.003 >
share|improve this answer
Your idea is good, but he said that he has lots of files, not only a couple of files. – Cristian Ciupitu Sep 18 '10 at 12:43
Not sure how the previous comment relates; both answers do it well, but you should definitely be using wild cards instead of explicitly listing them. – Andrew M. Sep 18 '10 at 13:11
True. The answer below is better. Btw, to do it on modification date, something like "cat ls -tr* >" would work. – Wouter de Bie Sep 18 '10 at 14:28
@Redmumba: yeah, I was referring to wildcards. – Cristian Ciupitu Sep 18 '10 at 15:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.