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.
3 Answers
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.

- 100,812
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.
-
The OP is using Dropbox, the backup is created on Dropbox's servers. RAID is serious overkill and not really relevant here. – terdon Apr 30 '14 at 11:41
-
@terdon you're right it's a bit overkill but since based on his question he seems to want to have another backup aside from dropbox, I mentioned it. :) – eakdev Apr 30 '14 at 11:45
-
no, I want to create link to the dropbox folder so that I don't have to copy paste every time I want to share something in dropbox – Unbound Apr 30 '14 at 12:50
-
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
~/Documents
and have those changes propagated to~/Dropbox/Documents
. If you do it the other way around you'd have to first delete the real Documents folder (you get a file exists error otherwise) or move it to~/Dropbox
and then link back again. This would also mean that if you ever deleted your Dropbox folder, you would loose all your Documents. – terdon Apr 30 '14 at 11:55rm bar/file1
? – Unbound Apr 30 '14 at 12:59