#Copy txt file into multiple folders using Wildcards

1 messages · Page 1 of 1 (latest)

still kayak
#

Good morning! I've hit a roadblock --
I'm trying to create a txt file, and in the same line, copy it into multiple folders. I know the appropriate wildcard is "*", but it's only targeting one folder when it shouldn't.
Here's what I've been using:
touch Grocery_List.txt | xargs -n 1 cp -v Grocery_List.txt ./0/

Here are the target folders:
momo@momo:~/Desktop$ ls -lh | grep /*0[1-4]
drwxrwxr-x 2 momo momo 4.0K Dec 10 07:52 Breads03
drwxrwxr-x 2 momo momo 4.0K Dec 10 08:30 Drinks04
drwxrwxr-x 2 momo momo 4.0K Dec 10 07:52 Meats01
drwxrwxr-x 2 momo momo 4.0K Dec 10 08:46 Veggies02

Here is the end result:
momo@momo:~/Desktop$ ls /home/momo/Desktop/0/
/home/momo/Desktop/Breads03/:

/home/momo/Desktop/Drinks04/:

/home/momo/Desktop/Meats01/:

/home/momo/Desktop/Veggies02/:
Grocery_List.txt

tender walrus
#

So to be clear, wild cards like * are (mostly, not always) shell globbing which means that the command prompt interprets them, then replaces it with whatever it thinks goes there before running the command.

still kayak
#

When I pasted it, I think the asterisks got omitted

#

touch Grocery_List.txt | xargs -n 1 cp -v Grocery_List.txt ./*0*/

#

Danggit

vital crown
still kayak
#

touch Grocery_List.txt && cp Grocery_List.txt /home/momo/Desktop/*0*/ is better?

vital crown
#

well that would copy everything to the last directory that gets expanded

#

you could use a for loop

#
for i in /home/momo/Desktop/*0*/; do
  cp Grocery_List.txt $i
done