copy 3 files to a directory and all subdirectories?
is it possible? i have 3 files that i need to copy to /mnt/hdb2 and all its subdirectories, and theres a lot of them....itd be nice if theres some sort of command that could do this for me...
i already tried cp -R file1 file2 file3 /mnt/hdb2/* and that failed misserbly... thx for the help, chris i dont think itd matter much, but im running debian linux on a 2.4 kernel... |
Try this:
Code:
for dir in `ls -d /mnt/hdb2`; do cp FILE $dir; done Code:
for dir in `ls -d /mnt/hdb2`; do cp FILE1 FILE2 FILE3 $dir; done |
it didnt work...seems to be a problem with the ls command...ls -d gives me this
Code:
ghettobox:/var/www/test# ls -d /mnt/hdb2/ ls -d actually doesnt even list the directories of / |
OK, try this:
Code:
for dir in `find /mnt/hdb2/ -name '*' -type d`; do cp FILE1 FILE2 FILE3 $dir; done |
ALMOST! some of the folders have spaces in the name...screws it up petty bad lol
it does copy it to the folders WITHOUT spaces though, so good job on that =] |
Well, I do not pretend to be clever with the command line, but I do know that if you have a filename (or directory name) with spaces, you can either "escape" the spaces, or, easier for you, put the "spaced name in quotes". So now you should be able to improve on scuzzman's one-liner.
I never use spaces in filenames - they are a pain. HTH |
OK - try this:
Code:
for dir in `find /mnt/hdb2/ -name '*' -type d | sed 's/ /\\ /'`; do cp FILE1 FILE2 FILE3 $dir; done |
What's wrong with a plain
for i in file1 file2 file3; do find /mnt/hda2 -type d -exec cp $i "{}"\; ; done |
Quote:
|
I know what was wrong with my first solution:
It ran find three times! :} find /mnt/hda2 -type d -exec cp file1 file2 file3 "{}"\; ; done Cheers, Tink |
All times are GMT -5. The time now is 04:52 AM. |