10

I am trying to find files that have a newline in the filename. But I can't figure out what pattern to use.

The following works, but is not very useful if I want to use it in indented code.

find . -name '*
*'

I tried these two and they only succeeded in finding filenames that contained the letter n:

find . -name '*\n*'
find . -name "*\n*"

Then I found how to write backslash escape sequences and tried this:

find . -name "*$'\n'*"

But that doesn't find anything. How should I write the pattern?

13

In shell scripting, everything is a string. You do need to quote the * to prevent filename expansion, but you don't want to put the backslash escape sequence inside double quotes.

You could just concatenate the strings by placing them right after each other.

find . -name '*'$'\n''*'

But for better readability, you can use ANSI-C Quoting for the whole string.

find . -name $'*\n*'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.