19

I made some links to files in a folder. When I added that folder to Dropbox, the links contained duplicate copies of the files linked to. Have you had this problem? Do you understand what is happening? Is there a solution?

To make this question clearer: In the "type" column of the file manager, before connecting to Dropbox, Link_to_notes was shown to be a link and the size was 32 bytes. After connecting to Dropbox, Link_to_notes was shown to be a plain text document and the size was 18.7 kB, the size of the notes file.

  • 2
    With Dropbox being a cross-platform solution, every other behavior would probably be even more confusing - how would it behave if you sync your folder with a Windows machine? – Sergey Jan 6 '13 at 23:11
14

DropBox follows symbolic links and treats them as directories. It's really useful for backing up without having to move files and directories into your DropBox directory.

$ ln -s ~/Documents/ ~/Dropbox/Documents
  • This could be a dangerous behavior. For example, if I delete the link from Dropbox directory, is there possibly any scenario that I could be accidentally deleting my original files or folders too? – Vicon May 24 '18 at 19:25
  • @Vicon, that's not dangerous behaviour, that's expected behaviour. But yes, to be clear, if you remove the symbolic link, the files will be removed from Dropbox too – Gregology May 26 '18 at 1:23
  • 2
    In Dropbox community, it has been stated over and over that Dropbox does not support symbolic links and strongly advice against using it. If you contact Dropbox customer support, they will ask you to remove any symbolic link before proceeding. Sure, people can still use it, but this is not a behavior intended by Dropbox, and can be dangerous (losing files), problematic (having duplicated files unintentionally synced, which is the problem asked to be solved in this question), as well as syncing performance issues, etc. – Vicon Jun 4 '18 at 21:30
  • @Vicon, symbolic links operate transparently for many operations: programs that read or write to files named by a symbolic link will behave as if operating directly on the target file – Gregology Nov 8 '18 at 22:17
7

The best way to do it is to store the files in the dropbox folder and symlink to them from outside...

So create ~/Dropbox/Documents and symlink:

ln -s ~/Dropbox/Documents ~/Documents

This stops dropbox getting confused and de-linking anything that is a link inside because you have all the things inside and instead when you want them elsewhere you link to them in dropbox. The basic rule is don't have any symlinks anywhere inside the dropbox folder...have them outside the dropbox folder and you'll have no problem.

I have dropbox on several ubuntu machines and have all my major top level folders actually stored in dropbox.

  • Why would Dropbox get confused? And how would Dropbox alter symbolic links? Symbolic links are automatically resolved by the file system – Gregology May 26 '18 at 1:30
5

dropbox will follow sym links to directories, but it will break a link (either sym or hard) to a file and replace it with a file.

2

TL;DR: Below is a way to get behavior quite similar to symbolic links, at the graphical user interface (GUI) level only, which is especially helpful if you don't want DropBox repeatedly copying the same files to different folders within the DropBox hierarchy just because you want to view them from different places (i.e., folder paths).

Background

More than once I've been burned by DropBox duplicating folders if I create a symbolic links (symlinks) within the DropBox folder hierarchy, even to the point of filling my account. As many have noted around the web, there's no real fix for DropBox's lack of treating symbolic links properly, which is unfortunate as it would not be hard for them to do so.

Workaround

One workaround I use, however, to achieve the equivalent behavior of symlinks within the DropBox hierarchy --- what others often refer to as "internal symlinks" --- without DropBox duplicating everything is to create the equivalent of a Windows shortcut file (i.e., a .lnk file in the MS ecosystem). I do so by creating a .desktop file that opens my system's file manager to the desired path. Thus, this workaround only works at the GUI level and only for XDG compliant systems (e.g., Ubuntu, GNOME-based systems, many others).

Example

For example, I'm reading up on advanced Python techniques for a new job I'm taking, and the PDFs I'm reading are stored on my DropBox folder for the GoodReader App (iOS) so I can read them both at my desktop and with my mobile devices. Rather than having to drill down to that folder (/home/morse/lib/active/GoodReader/Books/Python), I simply create a Python.desktop folder under /home/morse/Desktop with the following contents:

#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Name=Python
Exec=nautilus /home/morse/lib/active/GoodReader/Books/Python
Icon=/usr/share/icons/MacBuntu-OS/places/96/stock_folder.png
Terminal=false

(Note: Be sure to adapt the Exec=nautilus ... portion if you are using a file manager other than Nautilus, and of course you will want to adapt the Name=, Icon=, and path portion of the Exec= line for each "symlink" you wish to create.)

With this, I see a folder named Python on my desktop that acts just like a symbolic link --- that is, I double-click it and it opens the appropriate folder --- but only a small text file (e.g., Python.desktop) gets sync'd to DropBox and my other systems (as opposed to all the contents eventually being duplicated everywhere by DropBox).

As with other .desktop files, permissions must be set such that the file is both readable and executable (e.g., chmod 700 Python.desktop or chmod 755 Python.desktop) for the indicated icon to display and for double-clicking it to actually do anything.

Summary

In summary, then, I'll always have the actual files available somewhere within DropBox --- in this example, /home/morse/lib/active/GoodReader/Books/Python --- but I'll also have a desktop "shortcut" to it across all my linux-based systems for which I also have DropBox configured.

Of course, this workaround does not work at the command-line level, as a true symlink would.

That said, this does appear to be a novel workaround at the GUI level, one I've not seen posted elsewhere. So, I'm hopeful this approach can be of use to others.

  • This is genius! I have not seen a solution for internal symlinks until now! And this is super neat. Thank you for making my day! I should add that it should be fairly straightforward to make a command-line script, which parses a .desktop file and opens the file or folder that is symlinked, though you may not be able to "cd" into the directory directly. – Praveen Feb 25 at 17:44
0

Compress your links and save the compressed file to Dropbox

The previous replies are exhaustive and clear. I just suggest three workarounds, based on a single principle. The third looks more difficult but it is very efficient. The idea is: compress your symlinks to a tar file, which Dropbox will not treat as a link, and save it to Dropbox. The third way is almost as direct as copying your links directly to your Dropbox -- actually much faster than copying several links one by one.

I have some twenty symbolic links I normally use in my Lubuntu installation, e.g. for quick access to bash scripts saved in Dropbox, to external hdds, to documents frequently used, etc. They are all in my home dir and in Desktop and I find it convenient to have a Dropbox copy of them to use for other installations or when I dist-upgrade (that is, when I reinstall after trying to dist-upgrade ;).

1st way

You make a directory called MyLinks (say, in Documents) and copy all your home symlinks to it; if you have symlinks in other directories, make subdirs in MyLinks and copy your symlinks to them. For example, if the links you want to save are in home and in Desktop, copy the home links to MyLinks, make a dir called Desktop in it and copy the Desktop links to it. Then open a Terminal, cd Documents (provided that this is the directory where MyLinks is) and make a tar file:

tar -cvf MyHomeLinks.tar MyHomeLinks

(Remember to add the ".tar" extension to the tarfile name, or Ubuntu Archive Manager would refuse to open it.) If you do this, just be careful not to add the option -h (--dereference) to tar because it would precisely behave as Dropbox and compress the target files instead of the symlinks. (By the way, such a behavior would be welcome in most cases, esp. if one aims at portability, but it is not if one wants to save the symlinks as symlinks.)

The tar file would also include links that are temporarily broken, such as links to external hdds not currently mounted -- which is fine.

Save the tar file in your Dropbox. When you need the links back, copy the tar file to a directory in your file system (not within Dropbox), extract it (just right click and choose "Extract here") and copy your symbolic links back to the locations where you want them.

2nd way

If the symlinks you want to save have a univocal prefix (such as "MySl"...) you can very quickly make your tarfile in this way (unnecessary spaces added to prevent mistakes):

find   .   -name   "MySl*"|xargs  tar  cvf  MyLinks.tar

The single dot after "find" means the current directory: open the Terminal in your home dir (as by default). You can surely add a path to the tar file and you can issue the command from another directory that is not home: replace the "." with the path to your home/user. No need to make work directories as MyLinks above. Restoring the symlinks is also quick: you copy the tarfile to your home, right click on it and "extract here". However, before starting to prefix all the names of your symlinks, have a look at the next option.

3rd way (and best)

A very quick way for collecting all of your symlinks in a tar file is: open a Terminal in your home/user (which is default when you open a Terminal) and:

find  .  -type  l|xargs  tar  -cvf  AllLinks.tar

The drawback is, you get ALL of your links in it, including some mozilla or hplip symlinks you didn't even know you had. To avoid this and to copy all and only the symlinks from a specified list of directories without recursion, you write the list after "find" in the command above. Say you want to save the links from home/user and Desktop; you can write

 find /home/<USER>/ /home/<USER>/Desktop/ -maxdepth 1 -type l|xargs tar -cvf MyLinks.tar

"-maxdepth 1" is to prevent find from recursing through home. You can add a path to tarfile if you wish. Alternatively:

 find .  Desktop -maxdepth 1 -type l|xargs tar -cvf MyLinks.tar

If you are lazy and you want to use this often, you can add it as an alias to .bashrc or to .bash_aliases in your home dir (.bash_aliases is a very convenient way for collecting your aliases and, why not, saving them to Dropbox...). Just create a new empty file called .bash_aliases in your home dir (that is, /home/user), open it with a text editor and write the following line in it:

alias save_symlinks='find . Desktop -maxdepth 1 -type l|xargs tar -cvf MyLinks.tar'

Replace the directories after "find" with the ones of your choice and "save_symlinks" with a command name of your choice. To restore, open your File manager (if the path to the directories in the command above is not absolute, the tarfile must be in home/user), right click and extract.

If you do this, life is easier. All you have to do is:

SAVE: type save_symlinks in the Terminal, save the tarfile in your home to Dropbox; RESTORE: copy the file from Dropbox to your home dir, right click on it and select "extract here".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.