command-linewc

weird option of command wc


Command wc has an option --files0-from=F. According to the manual, it reads input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input. Why NUL-terminated names? Isn't it more convenient just separating the names with newline or space?


Solution

  • It's more convenient if you have filenames with spaces (or new-lines, or tabs) in them.

    This is sometimes used with find -print0 that outputs its list of files with \0 as a separator instead of spaces.

    $ find . -type f -print0 | wc -c --files0-from=-
    15 ./c d
    12 ./a b
    27 total
    

    xargs has a -0 option for similar reasons.