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.

  • What about mv -i <source>/* <destination>/ ?
    – Pandya
    Commented Jan 4, 2016 at 10:50
  • Thank you for trying to help but I need help with the terminal command line - are you saying create a new folder ! if so then for example my images could be in folders image 1 and image 2 while the new folder could be image 3 - so would the command line be like this - mv -i <image 1/image 2>/* <image 3>/ thanks
    – Smokeyone
    Commented Jan 4, 2016 at 11:58
  • No need to create folder, you can just use image 1 as source and image 2 as destination
    – Pandya
    Commented Jan 4, 2016 at 12:01
  • Thanks again - no luck I am afraid error message - what have I done wrong -xubuntu@xubuntu:~/Desktop$ - mv -i <image 1/image 2>/* <image 2>/ bash: image: No such file or directory xubuntu@xubuntu:~/Desktop$
    – Smokeyone
    Commented Jan 4, 2016 at 15:36
  • you should run mv -i image\ 1/* image\ 2
    – Pandya
    Commented Jan 4, 2016 at 16:08

3 Answers 3


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.
  • Thank you very much for your help - I have been reading up on command lines but find it hard going - however will keep at it - following your very clear instructions - success - all the images are now in one folder - duplicates as well I assume - so gthumb or another programme could find the duplicates - of course I can guess another command line would find the duplicates much easier -
    – Smokeyone
    Commented Jan 5, 2016 at 12:49
  • I'm glad I could help. Yes this moves the duplicates as well, mv doesn't know anything about file contents, only file names. If you want to find duplicates, I don't believe there are any built-in commands for this --- you would have to download a tool like ImageMagick for that.
    – gardenhead
    Commented Jan 5, 2016 at 18:21
  • This is what happens after years of saving images in folders and doing back ups of back ups - I used your command line to merge images after renaming one set of images with GPRename. Thanks again
    – Smokeyone
    Commented Jan 7, 2016 at 6:20
  • @Smokeyone if this answer has solved your problem, please indicate so with the checkmark next to it. Thank you!
    – Jeff Schaller
    Commented Aug 6, 2016 at 13:23

With a GUI

You don't have to use the command line if you don't want to! Any file manager out there will at least let you navigate between directories, create and remove directories, and move files. Some may be more sophisticated than others when a file in the source directory has the same name as a file in the target directory.

If you want to detect (and get rid of) duplicate images, you can use Geeqie. (Install your distribution's geeqie package.) It's an image viewer with a few nice features, including a persistent “directory mode” (showing you a list of images in the current directory, with thumbnails, and letting you navigate it easily), and duplicate detection (menu “File” → “Find duplicates”, then drag-and-drop all the images). You can also perform basic file manipulations (copy, move, remove, and a crude mass rename feature) on the currently selected image(s).

With the command line

If you do want to use the command line, gardenhead has written a nice primer. I'll add a bit more advanced stuff.

To move all files from folder1 to folder2 except when there's already a file by the same name in folder2, you can use

yes n | mv -i folder1/* folder2/

The files with a name conflict will be left in folder1, you can then examine them to decide whether you want to rename them or delete them.

If you want to rename the files to have unique names, there are a few stategies you can apply. If the images have EXIF data, you can rename the file to include extra information such as the date the photo was taken. Even if there's no EXIF data you might want to include some image characteristics such as the size. See How can I rename photos, given the EXIF data?, renaming images to include creation date in name, How to rename all files and add image size to file name, Batch rename image files by age plus add date and variable to filename, … for some possibilities. If you just want the files to have unique names, you can number them.

If you want to detect visually similar images with a command line utility, you can use findimagedupes (again, install your distribution's package).

  • Thank you for the information - next image phrase will be renaming with Exif data - I'll have to go through the link you mentioned - sure to be back when I get stuck - thanks
    – Smokeyone
    Commented Jan 7, 2016 at 6:23

If you have mv from gnu, you can move files from the foo directory to the bar directory, renaming existing files with the following command:

mv --backup=numbered foo/* bar

(you should test this on sample data before running this command on files you are afraid to loose...)

You must log in to answer this question.

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