Finding files with newlines in filename

I want to use grep to find files that have newlines in the filename. For example, I have a directory where I create three files:

$ touch file1
$ touch "file 2"
$ touch "file
> with
> newlines"
$ find
.
./file 2
./file1
./file?with?newlines

I now want to pipe the find output into grep and have grep detect the newline and hence only display the last file. I tried a few things including

$ find -print0 | grep -z "
"

but nothing brought the desired result yet.

I'd use the -name find option to match newlines:

$ find . -name \*$'\n'\* -print
./file?with?newlines
3 Likes

Thanks. This one works also now:

$ find . -name \*"
"\*
./file?with?newlines

Still... if anyone knows how to get the approach with grep to work... would be nice.

This is how you use grep:

$ find . -print0 | grep -z '[\n]'
./file
with
newlines
2 Likes

For me the following works better

find . -print0 | awk '$0~ORS' RS='\0'

In shell script it makes sense to set a nl variable:

nl="
"
find . -name "*${nl}*"
Moderator comments were removed during original forum migration.