Register
It is currently Sun Nov 23, 2014 11:14 am

recursiveCopy


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Mon Oct 16, 2006 10:49 pm   
User avatar

Joined: Mon Oct 16, 2006 10:41 pm
Posts: 2
Really simple script I made awhile ago for recursively copying an indexing PHP script into a directory tree on my webserver.

Instead of recursively copying files within directories to another location, this script copies a single file into every sub-folder of the destination.

Code:
#!/bin/bash
#
# recursiveCopy.sh
#
# Description:
#  Program that copies a specified file into a specified directory
#  recursively. In other words, it copies a file to a directory
#  and into each of its sub-directories
#

# Check for the right number of command line arguments
if [ $# != 2 ]; then
   echo "Usage: ${0} /path/to/file /path/to/directory"
   exit
fi

# Check to make sure the specified file actually exists
if [[ ! -e ${1} ]]; then
   echo "Error: File ${1} does not exist"
   exit
fi

# Check to make sure the specified directory exists
if [[ ! -d ${2} ]]; then
   echo "Error: Directory ${2} does not exist"
   exit
fi

# Search for directories inside the current directory, loop, copy
find ${2} -type d | while read DIR; do cp ${1} $DIR/; done


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP