Comments on: A Note About Removing Files With find(1) https://pthree.org/2011/12/20/a-note-about-removing-files-with-find1/ Linux. GNU. Freedom. Tue, 31 Oct 2017 18:00:46 +0000 hourly 1 https://wordpress.org/?v=5.0-alpha-42199 By: richard https://pthree.org/2011/12/20/a-note-about-removing-files-with-find1/#comment-116293 Wed, 21 Dec 2011 19:51:41 +0000 http://pthree.org/?p=2149#comment-116293 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 https://pthree.org/2011/12/20/a-note-about-removing-files-with-find1/#comment-116292 Wed, 21 Dec 2011 19:25:34 +0000 http://pthree.org/?p=2149#comment-116292 "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. http://en.wikipedia.org/wiki/Null_character

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 https://pthree.org/2011/12/20/a-note-about-removing-files-with-find1/#comment-116291 Wed, 21 Dec 2011 16:48:40 +0000 http://pthree.org/?p=2149#comment-116291 @patrick- Yes, you're absolutely right about "&&" versus ";". Updated.

]]>
By: Aaron Toponce https://pthree.org/2011/12/20/a-note-about-removing-files-with-find1/#comment-116290 Wed, 21 Dec 2011 16:48:11 +0000 http://pthree.org/?p=2149#comment-116290 @richard- I think you misunderstood the sentence. Please try reading it again (this time with some updates).

]]>
By: richard https://pthree.org/2011/12/20/a-note-about-removing-files-with-find1/#comment-116288 Wed, 21 Dec 2011 10:33:00 +0000 http://pthree.org/?p=2149#comment-116288 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.

Richard

]]>
By: patrick https://pthree.org/2011/12/20/a-note-about-removing-files-with-find1/#comment-116286 Wed, 21 Dec 2011 07:54:16 +0000 http://pthree.org/?p=2149#comment-116286 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)

patrick

]]>