How should I merge two folders on the same filesystem?

RansuDoragon

I have two directories that look something like the following but with many more files.

folder1/pic1.png
folder1/test/readme.txt

folder2/guest.html
folder2/backup/notes.txt

I want to "merge" these two so all the contents of folder2 end up in folder1 and folder2 gets removed. They are on the same filesystem and disk (ext4). I know all of the files are unique, would mv work fine here?

s'kiddie cat

The "rsync" command is useful for this. I do something like this:

rsync -PHACcviuma --copy-unsafe-links --exclude="*~"  folder2/  folder1/  &&  rm -fr folder2

All the flags are documented in the rsync man page; basically rsync won't replace newer files with older ones, and won't bother to copy any files that are duplicated in the destination. Otherwise it will copy things with the original metadata (timestamp, permissions, etc) preserved.

The rsync program will also include "hidden files" (names starting with "."), backups (ending with "~", etc) so I use the --exclude option to skip certain uninteresting file patterns.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I merge two folders in Windows?

From Dev

Merge two folders with the same tree (auFS)

From Dev

How can I merge two hasMany relations from the same table?

From Dev

How can I merge two hasMany relations from the same table?

From Dev

How do I merge two Home folders into one after reinstalling Ubuntu?

From Dev

How are there two identical folders in the same location?

From Dev

How do I keep two folders in the same computer synced with each other?

From Dev

How to merge two mdx queries when I have used same dimension & Same Measure

From Dev

How to merge two dictionaries with same key names

From Dev

how to merge two objects with same values?

From Dev

how to merge two mysql tables with same structure

From Dev

how to merge two column from same table

From Dev

How to merge two the same objects in Ruby

From Dev

How to merge folders and subfolders?

From Dev

How to merge folders and subfolders?

From Dev

How do I merge two CSV files based on field and keep same number of attributes on each record?

From Dev

How do I merge two unallocated, non-sequential partitions on the same logical disk?

From Dev

How do I merge two CSV files based on field and keep same number of attributes on each record?

From Dev

How can i merge two drives in same HDD uaing Windows 10 or Ubuntu?

From Dev

How do I merge two adjacent <span> together if they have the same class?

From Dev

How do I use NTFS links to merge folders A and B?

From Dev

How should I handle two QGLWidgets which only share the same shaders?

From Dev

How should I make multiple many to many relationships between the same two models?

From Dev

How should I assigned the same value to two different keys in this Perl hash?

From Dev

How should I deal with folders with "items as default view" in search results

From Dev

How should I deal with folders with "items as default view" in search results

From Dev

How can two files in one of my folders have the same name?

From Dev

Merge two filesystem after reinstalling Ubuntu

From Dev

Should I backup the ".svn" folders?

Related Related

  1. 1

    How can I merge two folders in Windows?

  2. 2

    Merge two folders with the same tree (auFS)

  3. 3

    How can I merge two hasMany relations from the same table?

  4. 4

    How can I merge two hasMany relations from the same table?

  5. 5

    How do I merge two Home folders into one after reinstalling Ubuntu?

  6. 6

    How are there two identical folders in the same location?

  7. 7

    How do I keep two folders in the same computer synced with each other?

  8. 8

    How to merge two mdx queries when I have used same dimension & Same Measure

  9. 9

    How to merge two dictionaries with same key names

  10. 10

    how to merge two objects with same values?

  11. 11

    how to merge two mysql tables with same structure

  12. 12

    how to merge two column from same table

  13. 13

    How to merge two the same objects in Ruby

  14. 14

    How to merge folders and subfolders?

  15. 15

    How to merge folders and subfolders?

  16. 16

    How do I merge two CSV files based on field and keep same number of attributes on each record?

  17. 17

    How do I merge two unallocated, non-sequential partitions on the same logical disk?

  18. 18

    How do I merge two CSV files based on field and keep same number of attributes on each record?

  19. 19

    How can i merge two drives in same HDD uaing Windows 10 or Ubuntu?

  20. 20

    How do I merge two adjacent <span> together if they have the same class?

  21. 21

    How do I use NTFS links to merge folders A and B?

  22. 22

    How should I handle two QGLWidgets which only share the same shaders?

  23. 23

    How should I make multiple many to many relationships between the same two models?

  24. 24

    How should I assigned the same value to two different keys in this Perl hash?

  25. 25

    How should I deal with folders with "items as default view" in search results

  26. 26

    How should I deal with folders with "items as default view" in search results

  27. 27

    How can two files in one of my folders have the same name?

  28. 28

    Merge two filesystem after reinstalling Ubuntu

  29. 29

    Should I backup the ".svn" folders?

HotTag

Archive