Quantcast
Channel: How to make two directories identical? - Ask Ubuntu
Viewing all articles
Browse latest Browse all 4

Answer by terdon for How to make two directories identical?

$
0
0

Just use symlinks:

ln -s ~/Documents ~/Dropbox/

That will create a directory in your $HOME/Dropbox that is actually a link to ~/Documents. This means that any changes you make to ~/Documents will also be visible in ~/Dropbox/Documents since the latter is just a link to the former.

Symlinks are simple tricks. You can think of the symlink as a virtual copy of the link's target. Any operations done on the link are actually applied to the target. The two are exact copies of each other. Deleting the link will not affect the target in any way. To illustrate, here's a simple example:

$ mkdir foo
$ touch foo/file1
$ tree
.
└── foo
    └── file1

1 directory, 1 file

So, we have a directory called foo that contains a file called file. Now, what happens if we create a link to foo?

$ ln -s foo bar
$ tree
.
├── bar -> foo
└── foo
    └── file1

2 directories, 1 file

OK, let's see the contents of bar:

$ ls bar
file1

What if we delete the file?

$ rm foo/file1
$ ls bar
$

The bar directory is now empty because it is just a symlink to foo so deleting foo/file1 also deleted bar/file1 because the two were the same file.

Conversely, deleting the link itself will not affect the original in any way because the link is just that, a link.


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>