Copy file into directories and sub-directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Copy file into directories and sub-directories
# 1  
Old 06-05-2009
Copy file into directories and sub-directories

Hello-

I need to copy a file into multiple directories, and each directory's sub-directories (of which there are 5)

Currently, the parent directory is set up like this:

dir1
sub-dir1
sub-dir2
sub-dir3
sub-dir4
sub-dir5
dir2
sub-dir1
sub-dir2
sub-dir3
sub-dir4
sub-dir5
dir3
sub-dir1
sub-dir2
sub-dir3
sub-dir4
sub-dir5
dir4
sub-dir1
sub-dir2
sub-dir3
sub-dir4
sub-dir5
etc (for 17 directories in all)

file.js

Similar posts seem to involve copying multiple directories and copying a file into several sub directories.

Unfortunately, I can't quite figure out how to get the file to not only cycle through all directories in the parent directory, but also all of the sub-directories within.
# 2  
Old 06-05-2009
Let's assume dir1, dir2, etc live off the same parent directory - call it parent.

Code:
find parent/dir1 parent/dir2 parent/dir3 [and so on to ] parent/dir17 -type d |
while read directory 
do
    cp /home/me/file.js $directory
done

-----Post Update-----

If dir1 .. dir17 are all of the directories:

Code:
cd parent
find . -type d |
while read directory 
do
    cp /home/me/file.js $directory
done

-----Post Update-----

If dir1 .. dir17 are all of the directories:

Code:
cd parent
find . -type d |
while read directory 
do
    cp /home/me/file.js $directory
done


Last edited by jim mcnamara; 06-05-2009 at 03:46 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Giving read write permission to user for specific directories and sub directories.

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. This is for Solaris. Please help. (1 Reply)
Discussion started by: blinkingdan
1 Replies

2. Shell Programming and Scripting

Switching between directories and mkdir/copy dir/file

I was trying to copy the files inside the path /home/user/check/Q1/dir/folder1/expected/n/a1.out1 and a1.out2 and a1.out3 to /home/user/check/Q2/dir/folder1/expected/n/ if n directory is not present at Q2/dir/folder1/expected/ then directory should be created first. And, script follow the... (5 Replies)
Discussion started by: Mannu2525
5 Replies

3. Shell Programming and Scripting

Copy directories in make file

LD:=C:/WindRiver/diab/5.9.3.0/WIN32/bin/dld.exe CFILES:=$(wildcard *.c) OBJFILES:=$(subst .c,.o, $(CFILES)) OBJ_PATH:=$(PRJ_PATH)/out/ ADDOBJFILES := $(addprefix $(OBJ_PATH),$(OBJFILES)) FILES:=C:/EB/tresos/workspace/Test_Spi/output/src copyfiles: cp ... (3 Replies)
Discussion started by: ushacy
3 Replies

4. Shell Programming and Scripting

Shell script to copy particular file from directories recursively

I have directory path in which there are several sub directories. In all these sub dir there will be one env.cnf file. I want to copy this env.cnf file from each sub dir's and place them in destination path by creating same filename as sub dir_env.cnf. After copying env.cnf files from source... (4 Replies)
Discussion started by: Optimus81
4 Replies

5. UNIX for Dummies Questions & Answers

copy file using unix in multiple directories

Hi All Genious, I want to copy a file name XYZ .In a directory /HOME/dir/IXOS1/dir1 which contain multiple directories named not in pattern want to copy the XYZ in all of the directories available on path /HOME/dir/IXOS1/dir1 . Thanks in advance . (2 Replies)
Discussion started by: mumakhij
2 Replies

6. UNIX for Dummies Questions & Answers

Using grep command to find the pattern of text in all directories and sub-directories.

Hi all, Using grep command, i want to find the pattern of text in all directories and sub-directories. e.g: if i want to search for a pattern named "parmeter", i used the command grep -i "param" ../* is this correct? (1 Reply)
Discussion started by: vinothrajan55
1 Replies

7. UNIX for Dummies Questions & Answers

help with simple unix file copy and output in directories

Hi, I am fairly new to unix, and am trying to copy all files with the name "*.cons" within a directory (and all of the many directories within it) to a new directory called "output". There are multiple nested directories, and I would like to just pull out the files with ".cons" and not the other... (5 Replies)
Discussion started by: euspilapteryx
5 Replies

8. Shell Programming and Scripting

Script for parsing directories one level and finding directories older than n days

Hello all, Here's the deal...I have one directory with many subdirs and files. What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file. A script for... (5 Replies)
Discussion started by: ejianu
5 Replies

9. UNIX for Dummies Questions & Answers

Copy single file to multiple directories

Please help - I need to copy a single file to multiple directories. Dir structure: Parent_Directoy Filename1 Child_Directory1 Child_Directory2 Child_Directory3 Child_Directory4 .... So I need to copy Filename1 to all of the... (2 Replies)
Discussion started by: kthatch
2 Replies
Login or Register to Ask a Question