0

I want to copy all the files that contain in their name the strings that are listed in a .txt file. How can I do it?

0

If the strings are listed in the text file one per line, you can run xargs with argument-file option (-a) and cp *"{}"*. ({} is the placeholder for the string in each line.

cd /path/to/original_folder
xargs -a strings.txt -I{} bash -c 'cp *"{}"* /somewhere/else'
  • Where do I have to specify the original folder? – Benedetta Dec 18 '18 at 16:24
  • Actually the ones are listed are part of directory names and I have to recursevely copy subdirectory and files in them..does this command do this? – Benedetta Dec 18 '18 at 16:26
  • 1
    No, it won't do that. My answer is doing what you have asked in the question. Please edit your question and add all details ... – RoVo Dec 19 '18 at 8:45

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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