Use grep to find content in files and move them if they match

前端 未结 9 942
无人共我
无人共我 2020-12-12 13:05

I\'m using grep to generate a list of files I need to move:

grep -L -r \'Subject: \\[SPAM\\]\' .

How can I pass this list to the mv command

9条回答
  •  死守一世寂寞
    2020-12-12 13:38

    grep -L -Z -r 'Subject: \[SPAM\]' . | xargs -0 -I{} mv {} DIR
    

    The -Z means output with zeros (\0) after the filenames (so spaces are not used as delimeters).

    xargs -0
    

    means interpret \0 to be delimiters.

    Then

    -I{} mv {} DIR
    

    means replace {} with the filenames, so you get mv filenames DIR.

提交回复
热议问题