Copying a single file to multiple directories
Hello folks,
I wanted to know if any of the users/mods know how to copy a file or folder to multiple destinations. I have a file and it needs to be copied to multiple subdirectories and its not easy to do it manually. anyway i can do it using cp or something similar. i was thinking my last option would be writing a bash code or something. if that the case plz gimme a few pointers how to write this specific code |
Code:
for i in /dir1 /dir2 /dir3 /dir4; do cp file $i; done |
cool. this might work. but is there a way to do it if i don't have the directory names? and thanks!
|
well yes i'm sure there is, but you'll need some information from somewhere... bash isn't psychic!
|
If you want to copy the file to subdirectories in /home , something like this may do...
Code:
find /home -type d -exec cp file.txt {} \; |
thanks.. i think its best if i just describe the problem. i have a picture in pics directory. there are sub directories in the pics directory. i need the picture to be copied to all my sub directories. thanks homey and acid_kewpie.
|
thanks anyways..i got the solution.
here it is for the record #!/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 02:22 PM. |