I want to delimit file paths by using the null character (NUL, \0, ...) just like for example find -print0 does.

I'm using bash and I tried the following without success:

find $1 -print0 > dircontent
cat dircontent | xargs -0 stat --format="%X %Y %Z %f %u %g %i %h \0%n\0%s" > dirstats

Seems like I', getting a literal '\' and a '0' instead of a null character.

  • It works fine. The \0s are in your format string. Nov 20, 2013 at 11:11
  • They're not nulls though. When I do cat dirstats they show as \0 and when I do cat -v dirstats they show as \0 too. Real null characters would not show with cat and would be displayed as ^@ with cat -v.
    – bug
    Nov 20, 2013 at 11:16
  • For me cat dirstats the nulls are removed when drawn on the terminal. cat -v dirstats gives me with ^@. Can you run the first line again. Also what are the filenames. If they end with \0 (A \ and a 0) then you would see this. Nov 20, 2013 at 11:37

2 Answers 2


--format only parses percent escapes and adds a newline at the end. --printf also parses backslash escapes and doesn't add a trailing newline.

<dircontent xargs -0 stat --printf="%X %Y %Z %f %u %g %i %h \0%n\0%s\0" > dirstats

I used // as a delimiter and then sed -in 's/\/\//\x0/g' dirstats to get what I want. I'd still prefer a less hackish solution.

You must log in to answer this question.

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