Not sure why you get that error.
find ./subdir/* -print0
--print0 was a typo) would output a big non-terminated line with a few NUL characters in it. Because it doesn't end in a newline character and because it contains NUL characters, it is not text, so the behaviour of text utilities like
sort is unspecified there. GNU sort, would treat it as one big line and add back the missing newline.
Maybe you're using busybox
sort which as far as I can tell treats those NUL characters on input as line separators as well but outputs lines terminated by newline characters.
xargs -0 expects NUL separated records. So with GNU sort,
xargs would treat the
sort output as the same list as generated by
find -print0 plus on spurious element consisting of that extra newline character added by
In the case of busybox
sort, because all NULs have been converted to newlines, there's only one record as far as
xargs -0 can tell, so it will call
cat with one huge filename containing newline characters.
Here, if you want to sort the list of filenames, you need either to use GNU
sort with its
find subdir -type f -print0 | sort -z | xargs -r0 cat > merge.txt
Or assume that filenames don't contain newline characters and run:
find subdir -type f | sort | tr '\n' '\0' | xargs -r0 cat > merge.txt
Since you used the
zsh tag, you may as well do everything in
zargs subdir/**/*(D.) -- cat > merge.txt
Which actually will provide you with a sorting order closer to what you're looking for.