Could we help you? Please click the banners. We are young and desperately need the money
We needed to copy all files that were modified within the past 28 days from all subdirectories to another place whilst maintaining the whole directory structure. This cannot be done with a simple unix command thus we needed to develop a small script for this.
The script accepts 3 parameters. Those are:
For the function to work you'll need to create a new file called copyfiles.sh and put the following code into it:
#!/bin/bash # $1 = file # $2 = source directory # $3 = destination directory FILE=`basename "$1"` SRC_DIR=`dirname "$1"` DEST_DIR=`echo "$SRC_DIR" | sed "s#$2#$3#"` if ! [ -d "$DEST_DIR" ]; then mkdir -p "$DEST_DIR" echo "Verzeichnis erstellt: $DEST_DIR" fi cp -vfp "$1" "${DEST_DIR}/${FILE}"
Save and exit. Now you'll need to make that file executable:
chmod 755 copyfiles.sh
Now comes the real magic. Please modify the following command to your needs. The example below would do the following:
find /path/to/sourceDIR -mtime -30 -exec ./copyfiles.sh '{}' '/path/to/sourceDIR' '/path/to/destinationDIR' \;