How to get the URL of Dropbox file from command line?

Obtaining the Dropbox Client

You can download the Dropbox client for Linux on Dropbox's Website.

This package will install both the Dropbox daemon (which automatically syncs files to a folder if you configure it to), and the dropbox command line utility.

Pure Command Line

NOTE: Due to changes made to the Public folder by Dropbox, the instructions below no longer work.

In order to obtain a link to a file in Dropbox from the command line, you must now use the sharelink command instead of puburl. For more information, please see jbrock's answer detailing the use of that command.

For more information about the changes to the Public folder, please see this Dropbox help topic.

Assuming you have the Dropbox client installed and in your path, you can get a link to a file in your Public folder using the command:

dropbox puburl <path-to-file>

For example:

dropbox puburl ~/Dropbox/Public/somepic.jpg

However, this will not work for files outside your Public folder, it will simply give the error:

Couldn't get public url: Unknown Error

For more information about the dropbox command line interface, you can read the unofficial wiki.

File Explorer Integration

Just in case you just want to avoid going to the website, instead of needing a pure command-line solution, here's an alternative method.

For URLs to files outside the Public folder, it seems you have to use either the website or use a plugin that adds Dropbox-specific functionality to your file manager. By default, Dropbox supports integration with the Nautilus file manager (aka GNOME Files) for the GNOME desktop environment.

If you have Dropbox integration with your file manager, you can right click on a file and choose the "Share Dropbox Link" item in the "Dropbox" submenu. This will copy a link into your Clipboard.

You can usually tell if you have Dropbox integration with your file manager if, when you browse to your Dropbox folder in the file manager, green check marks appear over synced files.

Depending on your Linux distribution, plugins for different desktop environments may be available in the package repositories. For example, on Linux Mint there are plugins available for Nemo (Cinnamon, package is nemo-dropbox) and Caja (MATE, package is caja-dropbox).


Dropbox recently added the ability to create a share link (not just puburl) from command line as well as other new CLI features. For me this is great news. I discovered today that Thunar Dropbox Plugin is causing Dropbox to crash for version 3.16.1. So, I am going to just integrate Dropbox CLI into my Thunar context menu via 'Configure custom actions...' I needed to use Dropbox's Python script for new features such as creating a share link to work. Here is the usage:

sharelink

dropbox sharelink FILE

Prints out a shared link for FILE.

  • FILE Absolute path to FILE

Be sure to read the first three paragraphs on this page before getting started. https://www.dropbox.com/en/help/9192

To add a context menu item in Thunar, I went to 'Edit' > 'Configure custom actions...' and added this command:

dropbox sharelink %f | tr -d '\n' | xsel -ib

Here is a script I have written that integrates Dropbox in Thunar. It could also be used for other file browsers.

Here is the output of: dropbox help

Dropbox command-line interface

commands:

Note: use dropbox help <command> to view usage for a specific command.

 status       get current status of the dropboxd
 throttle     set bandwidth limits for Dropbox
 help         provide help
 puburl       get public url of a file in your dropbox's public folder
 stop         stop dropboxd
 running      return whether dropbox is running
 start        start dropboxd
 filestatus   get current sync status of one or more files
 ls           list directory contents with current sync status
 autostart    automatically start dropbox at login
 exclude      ignores/excludes a directory from syncing
 lansync      enables or disables LAN sync
 sharelink    get a shared link for a file in your dropbox
 proxy        set proxy settings for Dropbox