6

I want to combine two or more files in Linux, so I am using the following command:

cat small_file LARGE_File LARGER_FILE > SUM_OF_FILES

However this runs very slow.

Does anyone know a Linux tool that combines the files in the fastest time?

Gaff
  • 18,569
  • 15
  • 57
  • 68
macki
  • 163
  • 1
  • 3

3 Answers3

7

You could try a variation on the dd command, such as:

dd if=small_file bs=4k of=SUM_OF_FILES

dd if=LARGE_FILE bs=4k of=SUM_OF_FILES oflag=append

dd if=LARGER_FILE bs=4k of=SUM_OF_FILES oflag=append
Gaff
  • 18,569
  • 15
  • 57
  • 68
  • this is what I'm trying right now, I'm having problem with the exact size –  Nov 22 '11 at 22:10
1

I've found mmv (Mass Move and rename - Move, copy, append or link Multiple files using wildcard patterns.) from this useful bash reference. So you could do:

cp small_file SUM_OF_FILES
mmv -a LARGE_File SUM_OF_FILES
mmv -a LARGER_FILE SUM_OF_FILES

(note: mmv isn't installed by default, use sudo apt-get install mmv)

CapelliC
  • 119
  • 4
0

Maybe

cat small_file >> LARGE_File

will do what you want? If you need LARGE_FILE to be unchanged

cp LARGE_File SUM_OF_FILES
cat small_file >> SUM_OF_FILES

is better, but this will only be slightly faster than your original code.

Gunther Piez
  • 123
  • 4