Same files to multiple drives


I have 7 new pictures, and 4 thumbdrives. In the thumbdrives I have a folder called Month/Photo/Pictures I would like to delete everything inside the Pictures folder (for all 4 thumbdrives) while leaving everything else intact, and then copy the 7 new pictures to the Pictures Folder for all 4 drives simultaneously… What would be the fastest easies way to accomplish this?


A shell script might be the quickest and easiest method. I haven’t written any in a while so I might not be the best person to write one up for you that’s guaranteed to work.


Probably two commands should do it. One to erase, and one to move the files. It would be interesting to do it in a shell script, but how would I know what the name of the newly inserted drives is?


Commands would work, I’m sure, I just usually go for something quick and reusable. I did the same with updating/upgrading FreeBSD, ports and packages. One command instead of a few each time I wanted to update. Then set it to auto run at log in and life is good.

I haven’t written any she’ll scripts since I’ve switched from Vanilla to TOS but I know I could always assume they were found at /dev/da*. Could write it to start at /dev/da0 (or wherever they are mounted) and write the files then move to /dev/da1, etc until it tells you that one doesn’t exist.

That’s at least where I’d start working on it and see how it goes.


I plugged three of them in and they are called da0, da1, ada1s1 every one is different. The only way that I have found so far is

echo ./autofs/da0/Month/Photo/Pictures ./autofs/da1/Month/Photo/Pictures ./autofs/ada1s1/Month/Photo/Pictures | xargs -n 1 cp  /usr/home/groot/Documents/Pictures/*

That doesn’t work to delete the files, but at least I have a way to copy them to multiple drives now.


Couldn’t you do something like

Blockquote rm ./autofs/da0/Month/Photo/Pictures/*

for each before you run the code you just posted.


I could, actually that is what I do is but that seems like a lot of work. I’m looking for an easier way.

rm -rf ./autofs/da0/Month/Photo/Pictures
mkdir -p ./autofs/da0/Month/Photo/Pictures
cp file1 file2 file3 ./autofs/da0/Month/Photo/Pictures



That would work to copy multiple files to the same drive. I’m trying to copy/delete the same files on multiple drives.

rm -rf ./autofs/$1/Month/Photo/Pictures
mkdir -p ./autofs/$1/Month/Photo/Pictures
cp file1 file2 file3 ./autofs/$1/Month/Photo/Pictures

and run it four times da0 da1 da2 da3

I probably can write a single shell expression with a loop. Would you like?


Yes! I would very much like that.


That’s for bash:
for d in "da0" "da1" "da2" "da3"; do rm -rf ./autofs/$d/Month/Photo/Pictures; mkdir -p ./autofs/$d/Month/Photo/Pictures; cp file1 file2 file3 ./autofs/$d/Month/Photo/Pictures; done


for d in "da0" "da1" "da2" "da3"; do
   rm -rf ./autofs/$d/Month/Photo/Pictures
   mkdir -p ./autofs/$d/Month/Photo/Pictures
  cp file1 file2 file3 ./autofs/$d/Month/Photo/Pictures

Sorry, didn’t test it. Pls backup your files etc.

If you’re after csh/tcsh, it probably won’t be a one-liner but rather a script. How badly do you want it to be a one-liner?