shell 将一个文件分别复制到1到10个目录下
可以使用循环语句来实现将一个文件复制到1到10个目录下的操作。以下是一个示例的Shell脚本:
#!/bin/bash
# 源文件路径
source_file="/path/to/source/file.txt"
# 目标目录的前缀
target_dir_prefix="/path/to/target/directory"
# 循环从1到10
for i in {1..10}
do
# 目标目录路径
target_dir="${target_dir_prefix}${i}"
# 复制文件到目标目录
cp "$source_file" "$target_dir"
done
在脚本中,你需要将/path/to/source/file.txt替换为你要复制的源文件的路径,将/path/to/target/directory替换为你的目标目录的路径前缀。然后,脚本将会将源文件复制到/path/to/target/directory1到/path/to/target/directory10这10个目录中。
原文地址: http://www.cveoy.top/t/topic/iFdN 著作权归作者所有。请勿转载和采集!