Home > linux > Merging folders on linux bash

Merging folders on linux bash

Recently I needed to merge two folders using the bash (terminal) on linux (flavor Ubuntu). I found that the best command for this task is rsync. Here is an example that I run before using the command:

  • created two folders named a and b.
  • created an empty file inside folder a named a.txt and other named t.txt with the content test.
  • created an empty file inside folder b named b.txt and other named t.txt with the no content.
  • I want to merge all files inside folder a to folder b. So I executed the command:
# running the command from where folders a and b are placed.
rsync -a --progress a/ b/
  • both / after the folders a and b are mandatory!
After that all files a.txt, b.txt and t.txt were in folder b. The command replaced the t.txt file from folder a over the one that was inside folder b, as desired. I could check that reading it contents and see that the word test was there.
Categories: linux Tags: , , ,
  1. Felix M.
    June 20, 2013 at 11:41 AM

    Thank you very much!

  2. jordi
    June 30, 2014 at 10:06 PM

    thanks for sharing

  1. No trackbacks yet.

Leave a comment