Handling filenames with spaces, carriage returns or other control characters

find -print0 | while IFS= read -rd $'\0' filename ; do echo "[$filename]" ; done

-print0, prints the full file name on the standard output, followed by a null character instead of the newline character.

IFS, is the "Internal Field Separator" that is used for word splitting after expansion. Here, IFS is set to null string.

-r, specifies that backslash "\" does not act as an escape character.

-d, is the delimeter. Which in this case is the null character '\0'.

$'\0', the $ prefixed single quoted string decodes the backslash escape character. In this case a null character.

[], is simply there to print out the text, so you notice any spaces in the beginning and end of text.

Post new comment

  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.
Comment