On Tue, Jan 13, 2004 at 01:59:10PM +0000, Barry Samuels wrote:
I have a /var/www directory which is a local copy of my web site. I want to copy only the .html files together with any sub-directories that contain .html files (retaining the directory structure), together with their files, into another directory.
I've tried various incantations involving 'find' and can only succeed in copying files from the base directory.
Right - using find and a small bash script I can do it ;) So, here goes, this has only been half tested, so I claim no responsibility if it manages to fry your cat, toast your grandmother, or, well, generally break things... Here's what I did...
(1) Create a shell script to copy a file with directory structure as follows: --- Begin ~/bin/copyfiles.sh Script Here --- #!/bin/bash
FILENAME=$1 DIRNAME=`dirname "$FILENAME"` DESTINATION="$2"
mkdir -p $DESTINATION/$DIRNAME cp $FILENAME $DESTINATION/$FILENAME --- End Script ---
(2) change in to the structure I want to copy (in my case ~/public_html/test/)
(3) run the find command, somewhat as follows... find . -name *.html -exec ~/bin/copyfiles.sh {} /some/base/destination ;
And that should work...
there's bound to be a more elegant solution, but that *appears* to work ;)
Cheers,
Brett