Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have 2 folders,

folderA having files [fileA, fileB, fileC, fileD] folderB having files [fileA, fileB, fileC, fileD, fileE, fileF, fileG, fileH, fileI, fileJ, fileK]

  1. I am currently in folderA. How do I know the list of files which are in folderB, but are not in FolderA.
  2. How to copy all such extra files into folderA?
share|improve this question
    
If I'm reading your question correctly, I think you're asking 1) "How to find differences in directory entries/listings?" and 2) "How do I merge the contents of two directories?". Am I right? –  gertvdijk Feb 6 '13 at 14:29
add comment

2 Answers

Question one can be answered with a combination of ls and diff:

Let's create some files:

dennis@lightning:/tmp$ mkdir A B
dennis@lightning:/tmp$ touch A/{c,d} B/{a,b,c,d}

And now we diff them:

dennis@lightning:/tmp$ diff -u <(ls A) <(ls B)
--- /dev/fd/63  2013-02-06 15:43:21.827691498 +0100
+++ /dev/fd/62  2013-02-06 15:43:21.827691498 +0100
@@ -1,4 +1,2 @@
+a
+b
 c
 d

As for question 2:

  cp -n B/* A

From the manpage:

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

So this will copy only missing files.

share|improve this answer
add comment

I don't know of any way to see which files are in folderA but not in folderB.

However, if mark and copy all the files from folderB to folderA you will be presented by a "Already exists" and get the options to skip (meaning it won't copy the already existing file in folderA from folderB) or to overwrite (overwrite the files from folderB into folderA)

share|improve this answer
    
I don't want to overwrite the existing files, since I will loose my changes. –  Joe Feb 6 '13 at 14:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.