Solved

UNIX - Copy one file into every directory on the box

Posted on 2012-03-19
6
296 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 76

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 76

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

759 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

18 Experts available now in Live!

Get 1:1 Help Now