Merge two image folders

filesimages

I have two image folders on my desktop both with around 600 images each.
Both folders have some duplicate images and some images with the same file name. How do I merge both together – I do not mind duplicate images or changed file name but I would like them in just one folder.

PS. I am very new to using the command line.

Best Answer

Since you are new to the command line I will go over the steps one by one, explaining each along the way.

When you open up a terminal/shell/command-line, you'll see a command-prompt like so:

username:~ $ 

or something similar. You'll almost certainly start out in your home directory, which has the name of your username.

Let's say your two image folders are folder1 and folder2. You said they are on the Desktop, so first we change to the Desktop directory:

cd Desktop

The cd command is the "change directory" command, doing exactly what it sounds like.

Now, we are going to use the mv command, which of course stands for "move".

mv -i folder1/* folder2/

I used the -i flag, which stands for "interactive", which causes a prompt to appear every time there is a file-name conflict. You'll be asked whether you want to overwrite the destination file or not.

After this, you'll have to manually resolve any conflicts* by renaming the files left in folder1 so they don't conflict with the files in folder2. Finally, run the above command again, but this time you should get no conflicts.

After all this, your folder1 directory should be empty, so go ahead and remove it with

rmdir folder1

and you're done!

I really recommend you go through a simple bash tutorial like this one to learn the basics.

  • Note that it is of course possible to resolve naming conflicts programmatically by renaming each of the files in folder1, but I tried to keep things simple.
Related Question