[英]How do I copy files in the same directory with a number changed of filename
I would like to copy mutiple files using patterns for a new file name. 我想使用模式为新文件名复制多个文件。
For example: 例如:
./happycat1_sm.png
./happydog1.png
./happyrat1.png
How do I copy these files into the following filename automatically using bash-script? 如何使用bash-script自动将这些文件复制到以下文件名中?
./happycat2_sm.png
./happydog2.png
./happyrat2.png
Many thanks 非常感谢
for file in $(find . -maxdepth 1 -type f); do cp "${file}" $(echo "${file}" | sed 's/1/2/'); done
这将复制当前目录中的所有文件,将1替换为2。由于它用于特定目的并且不是很可重用,因此它并不是真正有用,但也许正是您所需要的。
The below will copy files and rename the files in destination directory by replacing '1' with '2' 下面将复制文件并将目标目录中的文件重命名,方法是将“ 1”替换为“ 2”
#!/bin/sh
for file in src/*
do
cp "$file" dest/
mv -- "dest/$file" "dest/${file/1/2}"
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.