How To Keep OneDrive In Sync With A Folder On Linux Using OneDrive Free Client Fork

OneDrive is a file hosting and synchronization service offered by Microsoft, similar to Dropbox, Google Drive, MEGA, and so on. There's no official Microsoft OneDrive client for Linux, but it's still possible to keep your OneDrive files in sync (with real-time file monitoring) with a folder on your Linux machine, and this article will show you how, by using a fork of OneDrive Free Client that's still maintained (a command line OneDrive client for Linux).

OneDrive Free Client for Linux (fork)

A while back I wrote about mounting OneDrive in Linux using Rclone (with both business and personal accounts support). Some users might prefer keeping their OneDrive files in sync with a folder on their Linux machine (having the files on the disk after the sync is performed, allowing access even when the computer is offline), only uploading / downloading the changes instead of mounting OneDrive, and in this article we'll do just that using a fork of OneDrive Free Client.

The original OneDrive Free Client was abandoned in the autumn of 2018, but the tool was forked a few months later under the same name, being under constant development since then.

The OneDrive Free Client fork is a complete tool to interact and sync OneDrive on Linux, featuring:

  • State caching
  • Real-Time file monitoring with Inotify
  • File upload / download validation to ensure data integrity
  • Resumable uploads
  • Support OneDrive for Business (part of Office 365)
  • Shared folders (OneDrive Personal)
  • SharePoint / Office 365 Shared Libraries
  • Desktop notifications via libnotify
  • Dry-run capability to test configuration changes
  • Prevent major OneDrive accidental data deletion after configuration change

Like the original project, the OneDrive Free Client fork doesn't have a graphical user interface so it must be used from the command line, though it does have desktop notifications that let you know about the sync status and any sync error that occurs.

It's also important to note that while local changes are uploaded right away to the linked Microsoft OneDrive account, remote changes are delayed until the next synchronization when using --monitor (this 'monitor' mode allows the OneDrive Free Client to continuously monitor your local file system for changes, and upload them when detected). E.g. when running this tool as a service, the OneDrive Free Client monitor interval is 45 seconds, so it may take up to 45 seconds for remote changes to be synchronized to your local drive.

You might also like: Access OneDrive From Linux Using OneDriver (GUI)

As for shared folders, for OneDrive Personal accounts all you have to do is add them to your OneDrive. Do that by going to the OneDrive website and logging in to your account, then go to the Shared files list, right click on the folder you want to sync and then click Add to my OneDrive. For OneDrive Business or Office 365 accounts, shared folders are currently not supported.

How to install OneDrive Free Client (fork) on Debian (and Ubuntu, etc.), Fedora and more

This OneDrive client for Linux is available in the official repositories for some Linux distributions, but the version is not always the latest release. Check out the official instructions for installing an up to date version.

A OneDrive Free Client (fork) Docker image is also available.

How to use OneDrive Free Client (fork) to synchronize Microsoft OneDrive with a folder on your Linux machine

1. Authorize OneDrive Free Client (fork) for Linux with your Microsoft OneDrive account.

For Office365 / accessing a Sharepoint group drive in Office 365 business or education, please see the instructions from this page.

For personal accounts, open a terminal and run:


When you run it for the first time, the terminal where you ran 'onedrive' shows a message about authorizing this app by visiting a link. Copy the link shown in the terminal and paste it in a web browser. After logging in to your Microsoft account you should see a page asking you if you want to let this application access your information - click Yes.

After you click Yes, you'll reach a blank page. That's ok, it's supposed to be like that. You now need to copy that blank page's URL and paste it into the terminal where you're authorizing the onedrive tool with your OneDrive account.

After this, you'll see a message in the terminal saying that No OneDrive sync will be performed without either of these two arguments being present. This is because we didn't try to sync any files, we just authorized the onedrive application with your OneDrive account, so ignore it.

2. First synchronization between OneDrive and your local filesystem.

After authorization, you can perform a sync of your cloud OneDrive files to your local disk. The onedrive command line tool downloads all the OneDrive files in ~/OneDrive (a OneDrive folder placed in your home directory). You don't need to create this folder as the onedrive tool will create it for you.

Let's perform a dry run (trial sync) that performs no actual changes to make sure this OneDrive Free Client for Linux works correctly, by using:

onedrive --synchronize --verbose --dry-run

If everything looks good, let's start synchronizing your OneDrive files to the local ~/OneDrive folder. You can choose to either synchronize all your OneDrive files and folders with the local OneDrive folder (step 2A below) or only synchronize some files and folder (selective sync - step 2B below).

2A. To synchronize ALL your OneDrive cloud files to your local disk (to ~/OneDrive), use:

onedrive --synchronize

This is just for the initial sync. To have OneDrive Free Client for Linux run in the background and sync files when changes are detected, see step 3 below (enabling the systemd service).

2B. Enabling and using selective sync.

What if you want to sync multiple directories and files, but not all of them? Then you'll want to use the selective sync feature available with this OneDrive command line client for Linux.

Selective sync is a feature that allows specifying the files and directories to synchronize between OneDrive and your local filesystem, skipping all other directories and files.

It's very important to note that OneDrive Free Client for Linux doesn't remove any already synchronized directories or files from your disk in case you exclude them later via selective sync. What it does it exclude them from future synchronizations.

Example: if you only allow OneDrive to synchronize Folder1 and Folder2, if you later add Folder3 to your OneDrive directory on your computer, this Folder3 won't be synchronized with your OneDrive account; but if you have Folder1, Folder2 and Folder3 synchronized with your OneDrive account, then decide to only allow Folder1 and Folder2 to be synchronized, Folder3 won't be removed from the OneDrive directory on your Linux machine but any changes you make in this folder won't be synchronized with your OneDrive account.

You can enable selective sync for OneDrive Free Client by creating a file called sync_list in ~/.config/onedrive. Edit this sync_list file, and add the relative path to the files and directories you want to synchronize with OneDrive, each on a new line. All files and directories not matching any lines from this file will be skipped from syncing.

Example. Let's say I have many files and folders in my OneDrive account, but I only want to synchronize 2 directories, called Backup and Photos, and 3 files called file1.ods, file2.odt and file3.odt, all 3 files being in the Documents folder in my OneDrive account. In that case the ~/.config/onedrive/sync_list file would need to contain the following lines:


The first time you use selective sync, and every time after making any changes to the ~/.config/onedrive/sync_list file, you must perform a full re-synchronization using --resync, like this:

onedrive --synchronize --resync

If you have enabled the OneDrive Free Client systemd service (step 3 below) and it's currently running, you'll get an error when you attempt to run this command, saying Initializing the Synchronization Engine ... A database statement execution error occurred: disk I/O error. Segmentation fault (core dumped). In that case, you'll need to stop the onedrive systemd service, then run the resync command, and then start the service again, like this:

systemctl --user stop onedrive

onedrive --synchronize --resync

systemctl --user start onedrive

There are also options for skipping a directory, skipping files, dotfiles and symlinks, which are available via the OneDrive Free Client for Linux configuration file (see step 5 below).

Just like for the full regular sync, this is just for the initial sync. To have OneDrive Free Client for Linux run in the background and sync files when changes are detected, see step 3 below.

3. Enable the OneDrive Free Client for Linux systemd service.

To have OneDrive Free Client for Linux run as a service, so it automatically starts with your computer and it constantly watches for any OneDrive changes, synchronizing the changed files and folders, let's enable its systemd service.

When used as a systemd service, this OneDrive command line client for Linux runs in monitor mode (--monitor), which allows it to continually monitor your local file system for changes to files. With many files though, this can run into issues (unable to add a new inotify watch) caused by the local environment. The solution for this is to increate the number of max user watches. This page shows how to do that on Debian / RedHat or similar (Ubuntu, Fedora, etc.) and Arch Linux / Manjaro.

To enable and start the OneDrive systemd service (with notifications enabled) for your current (non-root) user, run:

systemctl --user enable onedrive

systemctl --user start onedrive

Check the OneDrive Free Client systemd service status with:

systemctl status --user onedrive

Only check the logs:

journalctl --user-unit onedrive -f

systemd-related: chkservice Is A systemd Unit Manager With A Terminal User Interface (New Version Available)

For other ways of running OneDrive service (as root user, via init.d), see its documentation.

It's very important to note that you should not remove the ~/OneDrive (or whatever path you're using for the OneDrive folder) folder while having the OneDrive Free Client fork systemd service running, as it will remove all your files from OneDrive (you will still have access to them on the OneDrive website, in the Recycle Bin).

5. (Optional) Configuration options.

In case you want to use a custom location for the OneDrive folder, you want to change the changed files monitoring interval, and much more, you can use the OneDrive Free Client configuration file.

On Debian, Ubuntu and derivatives, you'll find an example configuration at /usr/share/doc/onedrive/config. One other Linux distributions or if you can't find this config file, you can get it from the OneDrive Free Client GitHub project page - here's a direct link.

To change the default OneDrive Free Client for Linux configuration for your user, copy that config file to ~/.config/onedrive. E.g. on Debian/Ubuntu and other Linux distributions where this file is installed under /usr/share/doc/onedrive/config, copy it to ~/.config/onedrive using:

cp /usr/share/doc/onedrive/config ~/.config/onedrive/

Now to change some OneDrive Free Client options, open the ~/.config/onedrive/config file with a text editor. All the options in there are commented out (they have # in front of them); to change one of the defaults, uncomment the line, then set the value to what you want to use.

The options in the config file should be self-explanatory in most cases. For help, see the onedrive man page (man onedrive).

For more on using OneDrive Free Client on Linux, including how to use it with multiple OneDrive accounts, enabling proxy support for the OneDrive systemd service, and much more, check out the OneDrive Free Client Usage documentation.