Monday, 6 May 2013

UNIX: Copy a file to multiple subdirectories

I have a directory tree and in each of the lowest level directories, I
have a file called "attributes"

I've updated the contents of one of them, and want to copy it to the
other directories.

1. Find the files
find . -name attributes > target_directories.log

2. Edit "target_directories.log" and remove the "attributes" so it is
a list of subdirectories.




Do this in vi using:



We have to use the / in our search and replace, as doing


didn't seem to work

The "\" has to be there to escape the "/" character

3. Copy our updated file to other subdirectories:

cat target_directories.log |xargs -n 1 cp attributes

No comments: