简体   繁体   English

如何将文件名更改为数字的文件复制到同一目录中

[英]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.

相关问题 如何在linux中一次复制多个文件? 这些文件的源位置和目标位置是同一目录 - 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 can I recursively copy a directory into another and replace only the files that have not changed? 如何获得大型目录中特定文件的行数? - How do I get the number of lines for specific files in a large directory? 如何在bash中使用相同的名称但扩展名相同的目录复制多个文件? - How can I copy multiple files in the same directory with different names but same extension in bash? 如何在Linux中为多个文件重命名以更改相同的文件名元素? - How do I rename lots of files changing the same filename element for each in Linux? 如何检索 linux 中给定目录级别的所有文件。 我想要绝对路径以及文件名 - How do I retrieve all files in linux for given directory level. I want to absolute path aswell as the filename 如何将整个嵌套目录中的头文件仅复制到另一个目录,在复制到新文件夹后保持相同的层次结构 - How can i copy only header files in an entire nested directory to another directory keeping the same hierarchy after copying to new folder 如何将具有相同后缀的所有文件复制到另一个目录? -Unix - How to copy all the files with the same suffix to another directory? - Unix 如何将不同的内容文件从一个目录复制到另一个目录? - How do I copy differing content files from one directory to another? 如何将目录中的大量zip文件移动到bash中指定数量的多个子目录中? - How do I move a large number of zip files in a directory to a specified number of multiple subdirectories in bash?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM