follow up on How to find files that contain newline in filename? ,

I need to do some manipulation on the result, for simplicity lets suppose I need to chown them.

Tried following, but does not work:

# this is what I usually use, not work
find . -name '*'$'\n''*' -type d |  while read a; do chown www.www "$a"; done

# this is more standard way, still not work
find . -name '*'$'\n''*' -type d | xargs chown www.www '{}'

1 Answer 1


Get find to construct the command lines for you, without trying to re-parse lists of files:

LC_ALL=C find . -name $'*\n*' -type d -exec chown www:www {} +

On GNU systems at least, you also need the LC_ALL=C to make sure it also finds the files whose name is not valid text in the user's locale.

  • can find produce a callable file because I am currently not sure what I want to do with these files? e.g. find ... > x ; ./x
    – Nick
    Commented Dec 19, 2022 at 16:03
  • 1
    Not reliably. Do you really need to make a list of the files before you know what you want to do with them? Commented Dec 19, 2022 at 16:14
  • thanks. I found some way to do it with your help. thanks. did ls -r and inspected directory by directory (5000-6000 total, 2-3 min) before deleting these.
    – Nick
    Commented Dec 19, 2022 at 16:15
  • One can use -print0 to generate a list that can be further processed. NUL-delimited records are the interchange format used to transfer arbitrary lists of file paths or command line arguments. Commented Dec 19, 2022 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .