Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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*'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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