cp - How to get duplicate files numbered as file1.txt_1, file1.txt_2, file.txt_3 when copying in BASH? -
in script, need copy files several directories, 1 directory, e.g.:
$ dir dir1 dir2 dir3 output $ cp */* output/ sometimes, there files same name though:
$ ls dir1/* file1.txt $ ls dir2/* file1.txt $ ls dir3/* file1.txt how can copy of files different directories, single directory, without filenames changed whenever 2 files identical names placed in same directory? sample result:
$ cp */* output/ $ ls output/ file1.txt_1 file1.txt_2 file1.txt_3
a pretty simple way use --backup flag cp. files replaced rather leaving them, might sufficient. approach simple enough easy wrap alias around.
source ├── dir1 │ └── file1.txt ├── dir2 │ └── file2.txt ├── dir3 │ └── file1.txt └── dir4 └── file10.txt cp --backup=numbered source/dir*/* dest $ tree dest dest ├── file1.txt ├── file1.txt.~1~ ├── file10.txt └── file2.txt
Comments
Post a Comment