Tuesday, April 30, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1281  / 2 Years ago, sun, june 5, 2022, 3:20:43

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.


More From » filesystem

 Answers
7

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.


[#25537] Tuesday, June 7, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
imberst

Total Points: 370
Total Questions: 107
Total Answers: 123

Location: French Polynesia
Member since Tue, Jul 7, 2020
4 Years ago
imberst questions
;