Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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 @@

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

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

Your Answer


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.