Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 将一个文件复制到多个按顺序命名的文件_Shell_Terminal - Fatal编程技术网

Shell 将一个文件复制到多个按顺序命名的文件

Shell 将一个文件复制到多个按顺序命名的文件,shell,terminal,Shell,Terminal,这可能很明显,但我无法完成:假设有一个名为a1.xml的文件,我想再创建7个以序列号命名的副本(a2.xml,a3.xml)。我试图用不同的步骤来解决这个问题,但还是卡住了。有什么想法吗 谢谢最简单的: for f in a2 a3 a4 a5 a6 a7 do cp a1.xml $f.xml done 同样有效(给定命令seq)-如果需要500份副本,效果更好: for n in $(seq 2 7) do cp a1.xml a$n.xml done 或使用算术: i=2 while

这可能很明显,但我无法完成:假设有一个名为a1.xml的文件,我想再创建7个以序列号命名的副本(a2.xml,a3.xml)。我试图用不同的步骤来解决这个问题,但还是卡住了。有什么想法吗

谢谢

最简单的:

for f in a2 a3 a4 a5 a6 a7
do cp a1.xml $f.xml
done
同样有效(给定命令
seq
)-如果需要500份副本,效果更好:

for n in $(seq 2 7)
do cp a1.xml a$n.xml
done
或使用算术:

i=2
while [ $i -le 7 ]
do
    cp a1.xml a$i.xml
    ((i++))
done
等等。

最简单的:

for f in a2 a3 a4 a5 a6 a7
do cp a1.xml $f.xml
done
同样有效(给定命令
seq
)-如果需要500份副本,效果更好:

for n in $(seq 2 7)
do cp a1.xml a$n.xml
done
或使用算术:

i=2
while [ $i -le 7 ]
do
    cp a1.xml a$i.xml
    ((i++))
done
等等。

您可以:

for f in a{2..7}.txt; do
    cp a1.xml "$f"
done
你可以做:

for f in a{2..7}.txt; do
    cp a1.xml "$f"
done