The xargs command provides a list of command-line arguments to another command. When filenames are used as command-line arguments, use a zero-byte terminator for the filenames instead of the default space terminator. Filenames can contain space characters, which will be misinterpreted as name separators, causing a filename to be broken into two filenames (for example, New file.txt might be interpreted as two filenames New and file.txt). Using the zero-byte suffix option solves this problem. We use xargs to accept stdin text from commands such as grep and find. These commands can generate output with a zero-byte suffix. The xargs command will expect 0 byte termination when the -0 flag is used.
Create some test files:
$ echo "test" > file1
$ echo "cool" > file2
$ echo "test" > file3
The -l option tells grep to output only the filenames where a match occurs. The -Z option causes grep to use the zero-byte terminator (\0) for these files. These two options are frequently used together. The -0 argument to xargs makes it read the input and separate filenames at the zero-byte terminator:
$ grep "test" file* -lZ | xargs -0 rm