I'm looking for some sort of a command that I can use, to copy/append multiple files into one; but without shell redirection (I'd like to try it in call_usermodehelper, see similar issue in call_usermodehelper / call_usermodehelperpipe usage - Stack Overflow). I know I could otherwise use:

cat file1 file2 > file.merge

... but that requires shell redirection.

My findings so far:

  • Cannot use cat, as it's default stdout output cannot be redefined (through, say, command line argument) - and other than that, it's shell redirection
  • Cannot use dd in single invocation, as it can only accept one (and only one) if= input file argument
  • Cannot use cp, as it will treat multiple files individually, and cannot copy them all "merged" into a single location

So - is there any standard tool, that would allow me to do something like (pseudocode):

copytool -i file1 -i file2 -o file.merge

... such that the output file.merge represents file2 appended to file1 contents?

  • 2
    Why not invoke a shell for the redirection? Jun 4, 2013 at 20:06
  • 1
    Must it be a single command or would a sequence of commands be OK, too? Would a pipeline be OK? Jun 4, 2013 at 20:12
  • Thanks for the comment @IgnacioVazquez-Abrams - when I try to call the shell version from call_usermodehelper (from a timer loop in a kernel function), it seems to "skip" some calls; so for debugging purposes I wanted to try an alternative... as I'm not sure if "instantiating" a shell (and redirections) may represent too much overhead in that context, and an alternative is needed. Cheers!
    – sdaau
    Jun 4, 2013 at 20:14
  • Thanks for the comment, @HaukeLaging - I just wrote in the previous comment that I suspect the "shell instantiation" to be too slow for the kernel call context I'm trying it from - and I tried two dds, and those seem to be "skipped" from my timer function call as well. Which is why I'm looking for an alternative... Cheers!
    – sdaau
    Jun 4, 2013 at 20:16

1 Answer 1


You can do:

sed -n wfile.merge file1 file2


awk '{print > "file.merge"}' file1 file2


sh -c 'cat file1 file2 > file.merge'

(note that depending on the implementation, the first two may not work properly with binary files).

  • Many thanks, @StephaneChazelas - that is the sort of syntax that I needed (unfortunately, it didn't help with my kernel calls, as they are still being skipped - but at least now I know those "skips" are not due to shell redirections). Many thanks again - cheers!
    – sdaau
    Jun 4, 2013 at 20:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .