21 C
Texas
Muhammad Nabeel
Network and System Administrator

Sync MicroSoft OneDrive with Linux

OneDrive is a file hosting service and synchronization service operated by Microsoft. OneDrive allow users to store files and personal data in the cloud, share files, and sync files. Users can upload Microsoft Office documents directly to OneDrive. it is naturally suited to the Windows platform, but we can also connect it with Linux based machines. There are differnet tricks to do that and in this article you will learn how to connect/sync one drive with linux machines.

OneDrive Free Client

OnDrive free client is a CLI based tool that allows to sync linux with OneDrive cloud.

We have to install some dependencies for OneDrive. Use following commands for dependencies installation according to your linux distributtion.

Dependencies Ubuntu/Debian
sudo apt install libcurl4-openssl-dev
sudo apt install libsqlite3-dev
Dependencies Ubuntu 18
- Advertisement -
sudo snap install --classic dmd && sudo snap install --classic dub
Dependencies Ubuntu 17
sudo wget http://master.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list
sudo apt-get update && sudo apt-get -y --allow-unauthenticated install --reinstall d-apt-keyring
sudo apt-get update && sudo apt-get install dmd-compiler dub
Dependencies Fedora/CentOS
sudo yum install libcurl-devel
sudo yum install sqlite-devel
curl -fsS https://dlang.org/install.sh | bash -s dmd

Note: After dmd installation below message will be appeared. you need to run that command which shows in the message.

Run `source ~/dlang/dmd-2.084.1/activate` in your shell to use dmd-2.084.1.
This will setup PATH, LIBRARY_PATH, LD_LIBRARY_PATH, DMD, DC, and PS1.
Run `deactivate` later on to restore your environment.

Dependencies: Arch Linux
sudo pacman -S curl sqlite dlang

OneDrive Installation

git clone https://github.com/skilion/onedrive.git
cd onedrive
make
sudo make install

Configuration is optional. By default all files are downloaded in ~/OneDrive and only hidden files are skipped. If you want to change the defaults, you can copy and edit the config file into your ~/.config/onedrive directory.

mkdir -p ~/.config/onedrive
cp ./config ~/.config/onedrive/config
vi ~/.config/onedrive/config

Now we need to authorize onedrive so it can access our Microsoft OneDrive account. Just run below command:

onedrive

And it will ask you to visit given URL for authorization. visit that URL, login your Microsoft account and allow app to access your account.

Once done, you will be redirected to a blank page. just Copy that blank page URL and paste it into the terminal.

That’s it. Onedrive will start downloading all of your files from cloud to your local directory.

You can see in below screenshot that, OneDrive is synced and files/folders are showing there.

Available options:

sync_dir: directory where all files will be synced.
skip_file: any files or directories that match this pattern will be skipped during sync.
Patterns are case insensitive. * and ? wildcards characters are supported. Use | to separate multiple patterns.

Note: after changing skip_file, you must perform a full synchronization by executing onedrive –resync

Selective sync

Selective sync allows you to sync only specific files and directories. To enable selective sync create a file named sync_list in ~/.config/onedrive. Each line of the file represents a relative path from your sync_dir. All files and directories not matching any line of the file will be skipped during all operations. Here is an example of sync_list:

Backup
Documents/osradar.docs
Work/admin
demo.txt

OneDrive service

If you want to sync your files automatically, enable and start the systemd service:

systemctl --user enable onedrive
systemctl --user start onedrive
To see the logs run command
journalctl --user-unit onedrive -f
Check all available OneDrive commands
onedrive -h
- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article