Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

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.
0
MajorBigDeal
Asked:
MajorBigDeal
4 Solutions
 
arnoldCommented:
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
 
ozoCommented:
find / -type d -exec cp singlefile {} \;

find / -type name singlefile -exec rm {} \;
0
 
arnoldCommented:
The exec method will error out because of too many elements being passed. Using xargs might be a better choice.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TomuniqueCommented:
@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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now