Monday, September 16, 2019

command line - Advanced merge directory tree with cp in Linux

I need to:



  1. Copy all of a tree's folders (with all files, including hidden) under /sourcefolder/* preserving user privileges to /destfolder/


  2. If there is a conflict with a file (a file with the same name exists in destfolder), then



    • rename file in destfolder with a standard rule, like add "old" prefix to filename (readme.txt will become oldreadme.txt)

    • copy the conflicted file from source to destination



Conflicts between folders should be transparent - if same directory exists in both sourcefolder and destfolder, then preserve it and recursively copy its content according to the above rules.


I need also a .txt report that describes all files/folders added to destfolder and files that were renamed.


How can I accomplish this?

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...