移动具有相同名称的多个文件并快速重命名它们 [英] Moving multiple files with same name and renaming them on the fly
问题描述
我的ubuntu 16.04中有多个文件夹,其中包含图片.我想将所有图片移动到一个文件夹,然后使用相同的名称重命名所有文件.
I have multiple folders in my ubuntu 16.04 with pictures in them. I would like to move all pictures to one folder and rename all files with same name.
我可以轻松地从第一个文件夹中移动图片,但是如何从其余文件夹中复制图片而又不破坏(复制)所有相同名称的现有文件?
I can easily move pictures from first folder, but how do i copy pictures from rest of the folders without destroying (copying over) all existing files with same name?
我可以在终端中使用一些方便的oneliner吗?
Is there some handy oneliner that i could use in terminal for this?
推荐答案
cp 有一个有用的选项--backup=numbered
,该选项将带数字的后缀添加到文件名中,否则该文件将被破坏.
cp has a useful option --backup=numbered
that adds a numbered suffix to the name of a file that would otherwise be clobbered.
如果您的目录树包含重复的文件名,则可以将cp
与find
组合以折叠结构. (免责声明:我没有对此进行测试,因此请谨慎行事.)
If you have a directory tree containing duplicate file names, then you can combine cp
with find
to collapse the structure. (Disclaimer: I did not test this, so please tread with caution.)
find $SOURCEDIR -type f -exec cp --backup=numbered '{}' $TARGETDIR \;
谢谢:
- https://unix.stackexchange.com/questions/16669/copy-files-with-renaming
- Copy nested folders contents to one folder recursively (terminal)
这篇关于移动具有相同名称的多个文件并快速重命名它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!