March 2, 2016

mv/grep move multiplier files

"grep -l" can be used to get the list of files. Then you can use "xargs" to move the files, like this:

find . -type f | xargs -r grep -l "phrase" | xargs -r mv -t target-directory

Beware of special symbols in file names though. So this would be more appropriate if you are not sure about the file names:

find . -type f -print0 | xargs -0r grep -Z -l "phrase" | xargs -0r mv -t "target-directory"

source:
https://www.quora.com/How-can-I-use-grep-to-mass-move-all-files-that-contain-a-given-phrase-in-their-text

  • LinkedIn
  • Tumblr
  • Reddit
  • Pinterest
  • Pocket
DigitalOcean Referral Badge
Keep my site online & receive a $200 60-day credit at DigitalOcean for your VPS Hosting
Cheaper Games on Instant-Gaming
Creative Commons Licence Clicky