Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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'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?

share|improve this question
Why not invoke a shell for the redirection? – Ignacio Vazquez-Abrams Jun 4 '13 at 20:06
Must it be a single command or would a sequence of commands be OK, too? Would a pipeline be OK? – Hauke Laging Jun 4 '13 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 '13 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 '13 at 20:16
up vote 11 down vote accepted

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).

share|improve this answer
+1 for the sh part – michas Jun 4 '13 at 20:23
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 '13 at 20:26

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.