Solved

UNIX - Copy one file into every directory on the box

Posted on 2012-03-19
6
298 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
6 Comments
 
LVL 77

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 77

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I have a share on a Data Domain and my Windows Servers can access it, but my HP-UX box cannot 6 89
Skill Development 15 163
Sed question 2 69
Python Assistance 7 73
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

867 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now