7

I have two folders /var/first/app and /var/second/app. I have different files within both folders and few are same. I want to merge /var/second/app to /var/first/app. How can I do that?

David Foerster
  • 35,754
  • 55
  • 92
  • 145
P S
  • 313
  • 2
  • 3
  • 9

3 Answers3

15

This should do the trick:

rsync -av /var/second/app /var/first/app
Javier Arias
  • 468
  • 4
  • 12
  • 3
    I had to use `rsync -av /app/. app/.` or the app directory would exist inside the first/app. As so `/var/first/app/app`. Perhaps because the path was not fully qualified. – Rots Jun 24 '21 at 02:12
7

Use something like:

cp -r /var/first/app /var/second/
rm -r /var/first/app

or change cp -r to cp -a to preserve ownership and timestamps.

You can also use -i to make sure what is going on. it's going to prompt you before overwriting anything.

Ravexina
  • 54,268
  • 25
  • 157
  • 179
0

You may first backup your destination folder (just in case) :

cp -r /var/first/app /var/first/app.backup

If you don't care overwriting files :

cp -fr /var/second/app /var/first/app

It will copy recursively the second folder into the first one, overwriting files with same names.

If you don't want to overwrite existing files :

cp -nr /var/second/app /var/first/app

If all is ok, you can remove the backup :

rm -rf /var/first/app.backup