Solved

UNIX - Copy one file into every directory on the box

Posted on 2012-03-19
6
307 Views
Last Modified: 2012-03-22
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
Comment
Question by:MajorBigDeal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 78

Accepted Solution

by:
arnold earned 250 total points
ID: 37739696
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
 
LVL 84

Assisted Solution

by:ozo
ozo earned 125 total points
ID: 37739710
find / -type d -exec cp singlefile {} \;

find / -type name singlefile -exec rm {} \;
0
 
LVL 78

Assisted Solution

by:arnold
arnold earned 250 total points
ID: 37739857
The exec method will error out because of too many elements being passed. Using xargs might be a better choice.
0
Technology Partners: 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!

 
LVL 6

Assisted Solution

by:Tomunique
Tomunique earned 125 total points
ID: 37741927
@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
 
LVL 11

Author Comment

by:MajorBigDeal
ID: 37743789
Thanks for the great comments - I really do need multiple copies of the same file, not links.  This is a testing situation.
0
 
LVL 11

Author Closing Comment

by:MajorBigDeal
ID: 37755310
Thanks!
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question