3

I have a Documents file in my home directory as usual. Now in my dropbox folder I have created a new directory named Documents. Now is there any way such that this two could be same? i.e if I update any of this, both of them will be updated. I think it may be done by symlink, but the idea of symlinks is not clear to me about what it does.

terdon
  • 104,119
Unbound
  • 217

3 Answers3

1

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.

terdon
  • 104,119
0

Similar question: check this Automatically mirror a directory in Ubuntu

What you are trying to do is what RAID and other stuffs do, it would be great if you read about them maybe it will give you a better solution. Creating a backup for another folder in the same drive is not really good.

eakdev
  • 1
  • 1
0

I would suggest to use rysnc command :

rsync (stands for remote synchronization) is an open source tool for data transfers between Unix systems.

rsync synchronizes directories – makes one directory look (contain the same files and subdirectories) exactly like another one. by comparing them as per specified criteria (file size, creation/modification date or checksum) .

How to use rsync :

sudo rsync -az /pathof folder A /pathof folder B

sudo rsync -az /pathof folder B /pathof folder A

-a archive mode (implies recursive, copy symlinks as symlinks, preserve owner, modification times, group, owner, special and device files)

-z compresses the data

I would Suggest also to use watch command which will repeat rsync every interval of time , or use cron .

For more info about watch command : Here

Reference : Here

nux
  • 39,152