简体   繁体   English

需要一点帮助,我需要grep和copy的正确语法

[英]Need a little help, I need correct syntax for grep and copy

I currently have 3TB of data on a disk with small to medium files in hundreds of folders. 我目前在磁盘上有3TB的数据,在数百个文件夹中有中小型文件。 I need to find certain text files witch contain certain words ( more than one word ). 我需要找到某些文本文件,其中包含某些单词(不止一个单词)。 I've already tried grep-ping for them. 我已经为他们尝试了grep-ping。 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 ? 有什么方法可以将-exec cp -rv / estinationfolder放入语法中,并将所有结果复制到该文件夹​​中?

Yes , certainly there is a way. 是的,肯定有办法。

You can pipe the grep output to copy command and provide required destination directory. 您可以通过管道将grep输出复制到copy命令并提供所需的目标目录。

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 该脚本会将文件复制到destination_path变量中提供的目标路径

Best part with this is, it will copy the files while preserving the full path. 最好的部分是,它将在保留完整路径的同时复制文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM