问题
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?
Is there some handy oneliner that i could use in terminal for this?
回答1:
cp has a useful option --backup=numbered
that adds a numbered suffix to the name of a file that would otherwise be clobbered.
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 \;
Thanks go to:
- https://unix.stackexchange.com/questions/16669/copy-files-with-renaming
- Copy nested folders contents to one folder recursively (terminal)
来源:https://stackoverflow.com/questions/49152110/moving-multiple-files-with-same-name-and-renaming-them-on-the-fly