There are files:

\\test test\ te\\st 

find ~test/* -name '*\\*' , finds all files with \, then add find ~test/* -name '*\\*' | xargs -i{} chmod 777 {} find ~test/* -name '*\\*' | xargs -i{} chmod 777 {} , and I get an error that there are no such files, because there is already one \ in the arguments. In general, how to properly screen backslashes so that it is possible to apply rights through xargs?

  • supplemented the answer. - aleksandr barakin

1 answer 1

It’s probably easiest to use the find program’s -exec option:

 $ find где -name '*\\*' -exec chmod a=rwx {} \; 
  • '*\\*' - all files / directories containing at least one \ character will fall under this template (it is repeated twice to shield itself)
  • a=rwx is a human-readable synonym for the number 0777 , understood by the chmod program as the first parameter
  • -exec программа опции-параметры {} другие-опции-параметры \; - This is the syntax of the find program option -exec . if desired \; can be replaced by ';' . the main thing is that this dot-comma is shielded and not perceived by the shell as an operator connecting two shell commands.

although, of course, you can use the xargs program. only in order to exclude the interpretation of escaping and the like, it is necessary to pass through the pipeline between find and xargs a list separated by null characters, and not line feeds:

 $ find -name '*\\*' -print0 | xargs -0 -I '{}' chmod a=rwx '{}' 
  • -print0 - create a list separated by null characters
  • -0 - read list separated by null characters