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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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*'
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0