LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copying a single file to multiple directories (https://www.linuxquestions.org/questions/linux-newbie-8/copying-a-single-file-to-multiple-directories-174772/)

tgolly 04-26-2004 01:41 PM

Copying a single file to multiple directories
 
I want to copy a single file to a directory and all the subdirectories contained within the main directory. I want to be able to copy a file into about 10,000 folders, I need a quick way to do this, thanks.

7ux_spirit 04-26-2004 01:57 PM

i dont think there is any standard command for copying to multiple locations.
u may try making a shell script

tgolly 04-26-2004 03:12 PM

I'm not familiar with creating shell scripts, could anyone help me create one for this job, thanks.

7ux_spirit 04-26-2004 03:47 PM

This script should work.
I dont know whether i could make this script more simpler, expecially that text filtering part with awk, there could be simpler tools for that!

#!/bin/bash
#rec_copy.sh
#Usage:
# rec_copy.sh input_file target_dir
# copies 'input_file' recursively to all directories starting at 'target_dir'

if [ -z $2 ]; then
echo "usage: $0 input_file target_dir"
exit
fi

#for i in $(ls -R $2| grep :$ | awk -F":" '//{print $1}' )
for i in $(ls -R $2 | awk -F":" '/:$/{print $1}' )
do
cp $1 $i
done


All times are GMT -5. The time now is 06:46 AM.