I have a directory:


This directory contains two folders, folder_1 and folder_2. In folder_2 are links to files present in folder_1.

Now, I want to copy dir_1 into /home/username2/dir_2, and the links that are in the new folder_2 should point to the files that are in the new folder_1. So, the new directory /home/username1/dir_1 is completely independent from the old one /home/username2/dir_2.

Is that possible ?

  • possible duplicate of How to create a copy of a directory on Linux with links
    – José Luis
    May 19 '14 at 10:11
  • No. From that thread: "I'd like to make a copy of the directory and link to the original from the new one. [...] I'm wondering if there is a way to create a copy of a directory by linking to the original". That is not what I am trying to do.
    – William Abma
    May 19 '14 at 11:01

Yes, assuming that your question has somewhat mixed information about how the depencies actually should be (I presume here you've mixed dir_1 and dir_2 towards the end), rsync(1) will do that for you:

rsync -r -l /home/username1/dir_1/ /home/username1/dir_2/

Relevant switches being

-l, --links                 copy symlinks as symlinks
-r, --recursive             recurse into directories

Or you could just go with easiest possible choice, using -a which implies (among other things) -l and -r:

rsync -a /home/username1/dir_1/ /home/username1/dir_2/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy