UNIX - Copy one file into every directory on the box

Assuming root access, what would be a simple way to copy a single file into each directory on the box.  So if there were 1,000 directories, there would then be 1,000 copies of the file.

Conversely, what would be the simple way to remove the same files.
LVL 11
MajorBigDealAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
arnoldConnect With a Mentor Commented:
Do you really want 1000 copies of the same file, or would using hard links reference the same file in multiple locations?
Find . -type d | while read a; do
The -d tells it to find directories.
0
 
ozoConnect With a Mentor Commented:
find / -type d -exec cp singlefile {} \;

find / -type name singlefile -exec rm {} \;
0
 
arnoldConnect With a Mentor Commented:
The exec method will error out because of too many elements being passed. Using xargs might be a better choice.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
TomuniqueConnect With a Mentor Commented:
@arnold    find will only pass 1 arg at a time, so exec will be fine.  potentially eat a lot of disk space, but work.  

hard/soft links would be better if the file isn't going to be changing, Identifying the file-system splits would vary depending on OS, (unless you issued a df for each directory to see where it lived.... but, this would be nuts on large systems).
0
 
MajorBigDealAuthor Commented:
Thanks for the great comments - I really do need multiple copies of the same file, not links.  This is a testing situation.
0
 
MajorBigDealAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.