How can I use xargs to copy files that have spaces and quotes in their names?

后端 未结 22 1184
春和景丽
春和景丽 2020-12-02 03:49

I\'m trying to copy a bunch of files below a directory and a number of the files have spaces and single-quotes in their names. When I try to string together find

22条回答
  •  天涯浪人
    2020-12-02 04:26

    I ran into the same problem. Here's how I solved it:

    find . -name '*FoooBar*' | sed 's/.*/"&"/' | xargs cp ~/foo/bar
    

    I used sed to substitute each line of input with the same line, but surrounded by double quotes. From the sed man page, "...An ampersand (``&'') appearing in the replacement is replaced by the string matching the RE..." -- in this case, .*, the entire line.

    This solves the xargs: unterminated quote error.

提交回复
热议问题