0

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 '{}'

Kusalananda
  • 333,661
Nick
  • 125

1 Answers1

2

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.

Stephen Kitt
  • 434,908
  • 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 Dec 19 '22 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? – Stephen Kitt Dec 19 '22 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 Dec 19 '22 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. – Stéphane Chazelas Dec 19 '22 at 16:54