#!/bin/bash #### 批量替换wp项目代码中的文件 #### Author: chenpeiqing #### Date: 2025-01-07 # 指定源文件和目标目录 source_file="/opt/adweb3/config/wp-html.php" target_directory="/usr/local/wwwtemplate/" # 检查源文件是否存在 if [ ! -f "$source_file" ]; then echo "源文件不存在" exit 1 fi # 检查目标目录是否存在 if [ ! -d "$target_directory" ]; then echo "目标目录不存在" exit 1 fi # 获取目标目录的第一级子目录 first_level_subdir=$(find "$target_directory" -maxdepth 1 -type d -printf "%P\n") echo "获取到所有子目录:$first_level_subdir" # 如果目标目录下存在子目录,则复制文件到第一级子目录中 # 循环遍历子目录并复制文件 for subdir in $first_level_subdir; do cp -f $source_file $target_directory$subdir echo "Copied $source_file to $target_directory$subdir" done