![](/img/trans.png)
[英]How do I copy multiple files at once in linux? With the source and the destination locations of these files being the same directory
[英]How do I copy files in the same directory with a number changed of filename
我想使用模式為新文件名復制多個文件。
例如:
./happycat1_sm.png
./happydog1.png
./happyrat1.png
如何使用bash-script自動將這些文件復制到以下文件名中?
./happycat2_sm.png
./happydog2.png
./happyrat2.png
非常感謝
for file in $(find . -maxdepth 1 -type f); do cp "${file}" $(echo "${file}" | sed 's/1/2/'); done
這將復制當前目錄中的所有文件,將1替換為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.