5

I have a folder of large files. I want that folder to be in two different places at once - my Home documents, and my College documents folder.

I've done this with a symlink in the College folder to the Home folder.

Unfortunately, Dropbox syncs my College folder - and my file space was quickly used up.

Does dropbox follow hard links, and if so, how do I create one?

8
  • How is this about Ubuntu? Apr 12, 2016 at 17:35
  • 2
    @NickVolynkin I'm using dropbox on Ubuntu with Ubuntu hard links / symlinks. How is it not?
    – Tim
    Apr 13, 2016 at 0:12
  • it's Dropbox on Linux/Debian with Unix symlinks. Answers will be the same for any Linux distribution. Apr 13, 2016 at 18:29
  • @NickVolynkin Yeah? Are the answers valid for Ubuntu? Yes. So it's on topic. I'd suggest you read the help center before suggesting questions like this aren't allowed here (they are).
    – Tim
    Apr 13, 2016 at 18:34
  • 1
    @andrewlorien I found that Dropbox had a memory leak when a syncing was included, casing memory usage to double each hour, leaving a crashed computer in the morning.
    – Tim
    Nov 16, 2016 at 0:00

2 Answers 2

3

No, it doesn't.

When you update a file, Dropbox breaks all links. So in the example @Falk gives above, if he edited that file from a remote computer, when it synced back the link would be broken, and Dropbox would contain a new file called testfile (Falks conflicted copy).

The only link which works is a soft link where the original file is the one in the dropbox folder. Here's the script I used to test:

# symlink with target inside dropbox
echo "symbolic link test" > ~/Dropbox/symlinkToDropbox.txt
ln -s  ~/Dropbox/symlinkToDropbox.txt ~/symlinkToDropbox.txt
cat ~/symlinkToDropbox.txt
echo "edit target of symlink" >> ~/Dropbox/symlinkToDropbox.txt
echo "edit symlink" >> ~/symlinkToDropbox.txt 
cat ~/symlinkToDropbox.txt 
cat ~/Dropbox/symlinkToDropbox.txt 
# symlink with target outside dropbox 
echo "symbolic link test" > ~/symlinkFromDropbox.txt
ln -s ~/symlinkFromDropbox.txt ~/Dropbox/symlinkFromDropbox.txt  # relative symlinks don't work
cat ~/Dropbox/symlinkFromDropbox.txt 
echo "edit target of symlink" >> ~/symlinkFromDropbox.txt
echo "edit symlink" >> ~/Dropbox/symlinkFromDropbox.txt
cat ~/symlinkFromDropbox.txt 
cat ~/Dropbox/symlinkFromDropbox.txt 
# hard link with target inside dropbox
echo "hard link test" > ~/Dropbox/hardlinkToDropbox.txt
ln ~/Dropbox/hardlinkToDropbox.txt ~/hardlinkToDropbox.txt
echo "edit target" >> ~/Dropbox/hardlinkToDropbox.txt 
echo "edit linked file" >> ~/hardlinkToDropbox.txt 
cat ~/hardlinkToDropbox.txt 
cat ~/Dropbox/hardlinkToDropbox.txt 
# hard link with target inside dropbox
echo "hard link test" > ~/hardlinkFromDropbox.txt
ln ~/hardlinkFromDropbox.txt  ~/Dropbox/hardlinkFromDropbox.txt
echo "edit linked file" >> ~/Dropbox/hardlinkFromDropbox.txt 
echo "edit target" >> ~/hardlinkFromDropbox.txt 
cat ~/Dropbox/hardlinkFromDropbox.txt 
cat ~/hardlinkFromDropbox.txt 
#all of that works fine.  
#But now open all of those files from your dropbox folder on another computer and edit them
#Your dropbox will sync, your local versions of all those files will be updated, but NONE OF THE LINKED FILES WILL UPDATE
#The hard links are replaced and the old versions copied as "conflicted copies"
#The symlink where the dropbox file was the link is unlinked

#the symlink where the dropbox file is the original is the only one that works
10
  • So we could say that it breaks hardlinks in shared folders?
    – Falk
    Nov 17, 2016 at 1:52
  • Yes. Hard links are broken, and soft links inside Dropbox are broken - but not until the file is changed. Nov 17, 2016 at 1:57
  • So you have proven me wrong, what am I supposed to do in a case like this? I don't see the option to remove my answer, should I edit it? Is it possible (for the op) to change the accepted answer?
    – Falk
    Nov 17, 2016 at 2:04
  • I'll run this script tomorrow, it's 3o clock where I live.
    – Falk
    Nov 17, 2016 at 2:06
  • 1
    @Falk you can't delete an accepted answer. OP can accept another answer whenever they want. You can edit your answer to tell users to refer to this post instead.
    – muru
    Nov 17, 2016 at 2:19
2

Turns out this answer was mistaken, see Andrew's post for the correct answer.

Yes I does.

I've tested it with a standard free dropbox account with the dropbox folder in a btrfs volume.

The test was:

ln /media/username/volume/Documents/testfile /media/username/volume/Dropbox/testfile
ls -li /media/username/volume/Documents/testfile
ls -li /media/username/volume/Dropbox/testfile

The first number from the ls -li command shows th inode number, the number between the permissions and the username is the link counter (shows how many hard links the file has).

Immediately after running the ln command the dropbox try icon showed activity, and effectively uploaded the test file.

I've also tested to make a second hard link inside the Dropbox folder and it also uploaded the file, I'm not sure if it's aware that's only one.

My test file is a small 18KB .ods file, but it should also work larger files.

About hard links and inodes:

When you create a hard link of a file you are giving it just a second name in a different folder (or the same if you like to).

This is files are not really placed in folders they are on the hard drive identified by an i-node (depends on the file-system type).

So what are folders?

Folder are just lists also identified by an i-node that contain the names of the files and other folders that are 'inside' of them. Each element in this list point to it's corresponding i-node.

So if you create hard links both/all point to the same i-node and therefore all of them are just files (the same one).

Be aware that some apps refuse to do their job with files that have hard links. Other apps may accidentally or intentionally break hard links turning one file with say 2 names into two files with one name each.

Wikipedia gives us a more info:

https://en.wikipedia.org/wiki/Hard_link

https://en.wikipedia.org/wiki/Inode

To create hard links you can use ln which is a command lines tool, You can use it like this:

ln TARGET LINK_NAME

Where target is the existing file and link_name the new name of the file. When you are done you can check with ls -li the i-node number of the file and see that both links have the same number.

Here is the man page: http://linux.die.net/man/1/ln

8
  • 1
    I don't think this answers the question. The question is "Does dropbox follow hard links" and you don't mention dropbox at all, you just go on a tangent about what are folders and inodes, the OP never asked "what is a hard link?" they asked about dropbox. Am I missing some thing in this answer? because, right now, it does not seem to answer the question.
    – Mark Kirby
    Apr 12, 2016 at 7:53
  • 1
    The point is that hard links look to aplications just like files because that's what they are. So Dropbox or any other app won't distinguish if it's a hard link or just a file with one single path. If you understand hard links you'll understand that Dropbox won't care about how the file ended up in it's folder.
    – Falk
    Apr 12, 2016 at 10:05
  • But some things don't follow some links - does dropbox follow hard links (not do all apps, I need to know specifically).
    – Tim
    Apr 13, 2016 at 0:13
  • Sure? what app does not "follow" hard links?
    – Falk
    Apr 13, 2016 at 13:15
  • OwnCloud, a file syncing app.
    – Tim
    Apr 13, 2016 at 13:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .