-2

I want to traverse a filesystem and copy parts of it to another filesystem by creating symlinks instead of copying anything.

rsync would be ideal if it had something like a --local-copy-via-symlink option, because rsync's inclusion/exclusion filters would be the best way to specify what I want to copy.

I know I can do this with a script, but is there a clever command that does this already?

David M
  • 604
  • 4
  • 14

1 Answers1

2
  1. A symlink is not a copy of a file, the link is a pointer to another file.
  2. Changing the data either by using the filename or the link name does not result in a two different files, which would be the case with a real copy.
  3. Removing the original doesn't retain (a copy of) the data at the location of the symlink, instead you get what's called a broken symlink, something that points to file location that no longer exists.

Simply put, there is nothing "clever" to do.


EDIT

Instead of creating symlinks, Linux has the concept of a "bind" mount. Since Linux 2.4.0 it is possible to remount part of the file hierarchy some where else. The call is:

                 mount --bind olddir newdir

or fstab entry is:

                 /olddir /newdir none bind

After this call the same contents is accessible in two places. This preserves all existing permissions. but you don't have symbolic links either.

HBruijn
  • 72,524
  • 21
  • 127
  • 192
  • Thank you for letting me know what a symlink is! By "copy" I meant "link," because I don't actually want to make copies. I want to create symlinks. – David M Jul 24 '14 at 21:31
  • 1
    Ah semantics! You don'y want to copy files, and you want something more efficient than creating individual symlinks? – HBruijn Jul 24 '14 at 22:12
  • I've done this a slightly different way, but what I really wanted was to run rsync (or something similar with inclusions/exclusions) such that it created symlinks rather than copying files. (My response to your answer was kind of snarky, so I'll give you credit for a correct answer as an apology.) – David M Jul 25 '14 at 21:32