I have a question concerning the concatenation of two processes in the terminal. I have a folder with over 50.000 files. I used grep to look for those files containing a specific term:

grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files

which gives me a huge list like this:


I need to copy the resulting files into a new folder. I was thinking something like:

grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | cp * bio_files/

My try might not make any sense. I'm just starting with the terminal. I just want to copy the files resulting from my grep search into a new folder called bio_files. I realised that what I get from grep is just the names of the files. But I want to use those names as input for the cp command. Any help is highly appreciated.

1 Answer 1


Use xargs and the -t option of cp:

grep -inrl "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | xargs cp -t bio_files/

If your files might have spaces in their names, then make everything null-delimited:

grep -inrlZ "Bioethik_Debatte" /var/cqp/upload/heideko/import_files | xargs -0 cp -t bio_files/
  • Thank you. That worked! I'll read more about xargs! May 15, 2018 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.