$ find . -type f | xargs grep "koala" grep: ./te: No such file or directory grep: st/a.txt: No such file or directory
原因
就是因为文件或目录包含空白符
文档
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ man find -print0 This primary always evaluates to true. It prints the pathname of the current file to standard output, followed by an ASCII NUL character (character code 0).
-X Permit find to be safely used in conjunction with xargs(1). If a file name contains any of the delimiting characters used by xargs(1), a diagnostic message is displayed on standard error, and the file is skipped. The delimiting characters include single (`` ' '') and double (`` " '') quotes, backslash (``\''), space, tab and newline characters. However, you may wish to consider the -print0 primary in conjunction with ``xargs -0'' as an effective alternative. $ man xargs -0 Change xargs to expect NUL (``\0'') characters as separators, instead of spaces and newlines. This is expected to be used in concert with the -print0 function in find(1).