Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I would like to move a folder to another folder but I just want to merge the two folders. For example, say I have Folder B which has the ...
  1. #1
    Just Joined!
    Join Date
    Nov 2005
    Posts
    9

    merge folders together

    Hi,

    I would like to move a folder to another folder but I just want to merge the two folders.

    For example,
    say I have Folder B which has the following files in it
    - fileA
    - fileB
    - fileC

    Folder A has the following files in it
    - fileA
    - fileB
    - fileC
    - fileD
    - fileE

    And I want to move folder A to folder B.

    The objective here is to ensure that existing fileA, fileB and fileC are not replaced but fileD and fileE are to be copied across.

    Is there an easier way to do this in linux?

    I am running Ubuntu 10.04.

    Any help is greatly appreciated.

    Thank you in advance

  2. #2
    Linux User ptkobe's Avatar
    Join Date
    Feb 2008
    Location
    Torres Vedras, PT
    Posts
    274
    "The objective here is to ensure that existing fileA, fileB and fileC are not replaced but fileD and fileE are to be copied across."

    If that's really what you want, I can think on a shell script that does a copy file by file depending on file existence at the destination.

    You may consider if what you really need is not a synchronization tool. That will
    * add non-common files (or optionally deleting them) on both dirs
    * replace common based on date

    rsync is one of those tools. May not be very easy to use, but very powerful.
    Or you may google for synchronization tools

    Regards
    Luis

  3. #3
    Just Joined!
    Join Date
    Nov 2010
    Posts
    11

    Select SKIP ALL during Nautilus file copy

    Using Nautilus, select all files in Folder A. Then paste them into Folder B. Nautilus will ask you if you want to REPLACE any existing files in Folder B. Answer SKIP ALL and only files with unique names will be copied over. No existing files in Folder B will be replaced.

  4. #4
    Linux Enthusiast
    Join Date
    Apr 2004
    Location
    UK
    Posts
    658
    Hi there,

    The man pages for cp point us at the handy-dandy no-clobber flag (-n), which should do what you need.

    Code:
    chris@angua:~/dev/scratch$ ls -l dir*
    dir1:
    total 0
    -rw-r--r-- 1 chris chris 0 2010-12-02 09:59 fileA
    -rw-r--r-- 1 chris chris 0 2010-12-02 09:59 fileB
    -rw-r--r-- 1 chris chris 0 2010-12-02 09:59 fileC
    
    dir2:
    total 20
    -rw-r--r-- 1 chris chris 5 2010-12-02 09:59 fileA
    -rw-r--r-- 1 chris chris 5 2010-12-02 09:59 fileB
    -rw-r--r-- 1 chris chris 5 2010-12-02 09:59 fileC
    -rw-r--r-- 1 chris chris 5 2010-12-02 09:59 fileD
    -rw-r--r-- 1 chris chris 5 2010-12-02 09:59 fileE
    chris@angua:~/dev/scratch$ cp -n ./dir2/* ./dir1/
    chris@angua:~/dev/scratch$ ls -l dir*
    dir1:
    total 8
    -rw-r--r-- 1 chris chris 0 2010-12-02 09:59 fileA
    -rw-r--r-- 1 chris chris 0 2010-12-02 09:59 fileB
    -rw-r--r-- 1 chris chris 0 2010-12-02 09:59 fileC
    -rw-r--r-- 1 chris chris 5 2010-12-02 09:59 fileD
    -rw-r--r-- 1 chris chris 5 2010-12-02 09:59 fileE
    
    dir2:
    total 20
    -rw-r--r-- 1 chris chris 5 2010-12-02 09:59 fileA
    -rw-r--r-- 1 chris chris 5 2010-12-02 09:59 fileB
    -rw-r--r-- 1 chris chris 5 2010-12-02 09:59 fileC
    -rw-r--r-- 1 chris chris 5 2010-12-02 09:59 fileD
    -rw-r--r-- 1 chris chris 5 2010-12-02 09:59 fileE
    chris@angua:~/dev/scratch$
    Note that the files in dir1 are zero bytes long and the files is dir2 are five bytes long before the copy.

    Let us know how you get on.
    To be good, you must first be bad. "Newbie" is a rank, not a slight.

  5. #5
    Linux User ptkobe's Avatar
    Join Date
    Feb 2008
    Location
    Torres Vedras, PT
    Posts
    274
    nice work, kakariko81280

    man cp
    -n, --no-clobber
    do not overwrite an existing file (overrides a previous -i option)

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...