0

I currently have 3TB of data on a disk with small to medium files in hundreds of folders. I need to find certain text files witch contain certain words ( more than one word ). I've already tried grep-ping for them. This works as it prints the path to every file. But this is a long list and I'm now looking for a workable way to copy them to another folder.

any ideas ?

Is there some way to put -exec cp -rv /estinationfolder in the syntax and have it copy all results to the folder ?

rene
  • 41,474
  • 78
  • 114
  • 152
DeWarrior
  • 1
  • 1
  • You don't mention this in your question: is a file a match if it contains all of the words, or is it a match even if only contains any one of them? – sanmiguel Feb 13 '14 at 13:47

1 Answers1

0

Yes , certainly there is a way.

You can pipe the grep output to copy command and provide required destination directory.

Here is a example,

find . -type f | xargs grep -l "textToSearch" | cpio -pV $destination_path

this script will copy files to destination path provided in destination_path variable

Best part with this is, it will copy the files while preserving the full path.

Mohit Chawda
  • 53
  • 1
  • 1
  • 8