Created
May 18, 2024 11:40
-
-
Save qichunren/5f37ca074ec6333f155c305d185cd9df to your computer and use it in GitHub Desktop.
在Linux中,我有两个目录,我需要从一个目录中同步其中的一些目录和文件到另一个目录中。 如第一个目录中有大量目录有文件,我需要选择性的记录一些目录和文件,我希望能同步其中的一些目录和文件到另外一个目录里,同时保证目录结构。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 源目录 | |
source_base="/data/tian5.0he/T113-tina5.0" | |
# 目标目录 | |
target_base="/home/qichunren/code/T113-S3-Box-SDK" | |
# 需要同步的目录列表 | |
directories_to_sync=( | |
"device/config/chips" | |
"openwrt/target" | |
) | |
# 需要同步的文件列表 | |
files_to_sync=( | |
"kernel/linux-5.4/drivers/mtd/awnand/spinand/physic/id.c" | |
) | |
# 遍历目录列表并执行同步 | |
for dir in "${directories_to_sync[@]}"; do | |
# 创建目标目录(如果不存在) | |
mkdir -p "${target_base}/${dir}" | |
# 执行 rsync 同步 | |
rsync -av --progress "${source_base}/${dir}/" "${target_base}/${dir}/" | |
done | |
# 遍历文件列表并执行同步 | |
for file in "${files_to_sync[@]}"; do | |
# 获取文件所在目录 | |
file_dir=$(dirname "${file}") | |
# 创建目标文件所在目录(如果不存在) | |
mkdir -p "${target_base}/${file_dir}" | |
# 执行 rsync 同步文件 | |
rsync -av --progress "${source_base}/${file}" "${target_base}/${file}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment