0

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?
1
  • 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, 2013 at 14:29

2 Answers 2

4

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.

0

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)

1
  • I don't want to overwrite the existing files, since I will loose my changes.
    – Joe
    Feb 6, 2013 at 14:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .