I code a lot in my dropbox folder to keep them synced across my devices (before git commits are viable) and unfortunately dropbox does not include an automatic way to exclude syncs. Each "node_modules" or "debug" folder contains potentially thousands of small files and syncing them is a waste of time and disk space. What's worse, dropbox falters when there are many thousand small files to sync and ends up halting (see here), at least on linux distros I am using.
I wrote this script to help me exclude directories from syncing. I have set up a job in cron to run every 5 minute and exclude pesky large folders that should not be synced in the first place.
Ideally this script should be implemented by dropbox itself as a feature similiar to how a ".gitignore" file works. I opened an issue on dropbox forums and seems like someone already requested this a full 10 YEARS ago! In the meantime, this is what we got.
A bash script to easily exclude directories from Dropbox sync using pattern matching. This tool works with the Dropbox CLI to help you manage which directories should be excluded from syncing.
You can install manually, or use the following commands to download and make the script executable:
curl -o dropbox-exclude.sh https://raw.githubusercontent.com/kavehtehrani/dropbox-exclude/master/dropbox-exclude.sh
chmod +x dropbox-exclude.sh
- Dropbox desktop client installed
- Dropbox CLI accessible in your path
- Bash shell
Note: I have only tested this on linux. Should work on MacOS as well. Windows, well I don't think you would be reading this if that were the case.
./dropbox-exclude.sh --pattern <glob-pattern> [--recent <minutes> | --ever] [--y]
--pattern <pattern>
: (Required) Glob pattern to match directories (e.g., "node_*")--recent <minutes>
: Only search directories modified in the last n minutes--ever
: Search all directories (default)--y
: Proceed without confirmation--remove
: Remove matching directories from exclusion list (so that they resync)
Exclude all node_modules directories:
./dropbox-exclude.sh --pattern "node_modules"
Exclude recently modified build directories (last hour):
./dropbox-exclude.sh --pattern "*build*" --recent 60
Exclude all dist folders without confirmation:
./dropbox-exclude.sh --pattern "*dist*" --ever --y
Remove all previously excluded node_modules directories from exclusion list:
./dropbox-exclude.sh --pattern "node_modules" --remove
I personally use this script in a cron job to run every 5 minutes as:
*/5 * * * * ~/Dropbox/.dropbox-ignore.sh --recent 5 --pattern "node_modules" --y
- The script searches your Dropbox directory for folders matching your specified pattern
- It can either search all directories or only recently modified ones
- Shows you a preview of directories that will be excluded
- Asks for confirmation (unless --y flag is used)
- Uses the
dropbox exclude add
command to exclude each matching directory - Finally displays the current exclusion list
- Requires explicit pattern specification
- Shows preview before executing
- Requires confirmation unless auto-confirm flag is used
- Rerunning the script will not duplicate exclusions
This script uses the Dropbox CLI's exclude command. Make sure you have the Dropbox command line interface properly installed and working before using this script.
You can always check your current exclusion list by running dropbox exclude list
in your terminal.
Happy to receive feedback and contributions!