Laura
Laura

Reputation: 67

Copying a list of files with wildcards into a new folder

I don't have much experience with the command line, but essentially I have a list of files in a single folder as follows:

file1_a_1
file1_a_2
file2_b_1
file2_b_2
file3_c_1
file3_c_2

And I also have a text file with the files I want. However, this list does not have the full file path, instead, it looks like this:

file1_a file3_c

because I want to move all files that start with 30 or so specific codes (i.e. everything that starts with file1_a and file1_c for all the files that start with this).

I have tried:

cp file1_a* file3_c* 'dir/dest'

but this does not work. I have also tried the find command. I think I have to use a loop to do this but I cannot find any help on looping through files with a wildcard on the end.

Thanks in advance! I am working on a linux machine in bash.

Upvotes: 1

Views: 571

Answers (1)

zahraa
zahraa

Reputation: 94

you can use the xargs command with find command and a pipe

find / -name xxxxx | xargs cp /..

Upvotes: 1

Related Questions