#!/bin/bash source=$1 target=$2 #$1を転送元$2を転送先とする txt=quiz1.txt #出力先のファイルを指定。 for loop in ${source}* do echo $loop ty=`file -b $loop` #loopのファイルタイプを引き数として入力 if [ -d $loop -o "$ty" = 'Bourne-Again shell script text executable' ];then chmod 775 $loop #スクリプトファイルかディレクトリならモードを775に変更。 find $source -type f -exec chmod 664 {} \; find $source -name "*.sh" -exec chmod 775 {} \; else chmod 664 $loop #それ以外のファイルならモードを664に変更。 fi cp -r -p $loop $target done cp -r -p ${source}* $target #すべての転送元データを転送先にコピーする。このときファイルの属性は保存され、ディレクトリ内のファイルも同時にコピーされる。 ls -l $source |tee $txt #転送先のディレクトリの中身を確認する echo from $sorce to $target |tee -a $txt #移したいファイルのあるディレクトリから転送先のディレクトリへ