Comments on: A Note About Removing Files With find(1) Linux. GNU. Freedom. Sun, 13 May 2018 18:21:35 +0000 hourly 1 By: richard Wed, 21 Dec 2011 19:51:41 +0000 Aaron, I think that the confusion is as @Flimm mentions that NUL is not the same as whitespace. To quote the xargs manpage:

"-0 Input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally)."

Regards, Richard

By: Flimm Wed, 21 Dec 2011 19:25:34 +0000 "the proper handling of NUL characters in your filename, such as spaces, tabs or the newline character"

The space character (U+0020), the tab character (U+0009) and the newline character (U+000A) are all examples of whitespace. They are not the NUL character.

There is only one NUL character (U+0000). In ASCII and in UTF-8, in is encoded as a single byte with the value zero.

The NUL character and the forward slash character are the only two banned characters in a filename. Because the NUL character/byte is guaranteed not be found in a filename, you can separate a list of filenames with a NUL byte. This is why -print0 is considered safe.

By: Aaron Toponce Wed, 21 Dec 2011 16:48:40 +0000 @patrick- Yes, you're absolutely right about "&&" versus ";". Updated.

By: Aaron Toponce Wed, 21 Dec 2011 16:48:11 +0000 @richard- I think you misunderstood the sentence. Please try reading it again (this time with some updates).

By: richard Wed, 21 Dec 2011 10:33:00 +0000 Hi Aaron,

You say

-- begin quote --
because of “-print0″ as a find(1) argument, and “-0″ with xargs(1), we can handle files with NUL characters
-- end quote --

But this is not correct. the -0 uses a NUL character to terminate the name of each file when passing between find and xargs. This allows files with whitespace, quotes and similar special characters to be deleted. But it does not allow files with a NUL character in the name.


By: patrick Wed, 21 Dec 2011 07:54:16 +0000 hi,

you should improve your last command like so

cd /path && find . -print0 | xargs -0 rm -rf

to avoid deleting all files from the cwd if the cd fails (e.g. due to spelling mistake although i guess one would use tab completion of the terminal anyway)...

you could also use the find command to delete many files like this

find /path -exec rm -rf {} +

which builds the args for rm like xargs (check man page)