keepcalculator

06 Numbers and Powers

Backup Clipboard History KDE Widget

Card No. 06·31977 · Updated · Standard formula, shown below

The KDE clipboard widget (Klipper) does not have a built-in backup feature, but you can manually copy its history file or set up a simple automatic backup using a cron job or a file-syncing service. This article explains where Klipper stores its history, how to back it up, and how to restore it.

Where Klipper Stores Clipboard History

Klipper saves its clipboard history in a file named history inside the ~/.local/share/klipper/ directory. This is a plain text file where each line is a separate clipboard entry. The file is updated in real time as you copy new items, so it is always current when you read it.

To see the file yourself, open a terminal and run:

ls -la ~/.local/share/klipper/

You should see the history file along with a few others like history2 (used in some versions) and a lock file. The exact filename can vary slightly between KDE Plasma versions, but the directory is consistent.

Why a Simple Copy Is Not Enough

If you just copy the history file to a USB stick, you get a snapshot of the clipboard at that moment. That works for a one-time backup, but it does not protect you from losing new items you copy after the backup. For continuous protection, you need to either:

  • Copy the file on a schedule (e.g., every hour with cron), or
  • Use a file-syncing service that watches the directory and uploads changes automatically.

Also, Klipper may lock the file while it is running, so a naive cp might occasionally fail if the file is being written at that exact moment. Using cp with a short retry loop or syncing the entire directory avoids this.

How to Manually Backup the Clipboard History

The simplest way to back up is to copy the entire ~/.local/share/klipper/ folder. Here is a step-by-step manual method:

  1. Close Klipper (right-click the tray icon and select Quit) to ensure the file is not locked.
  2. Open a file manager and navigate to ~/.local/share/.
  3. Right-click the klipper folder and select Copy.
  4. Paste it into your backup location (external drive, cloud folder, etc.).
  5. Restart Klipper by running klipper in a terminal or logging out and back in.

If you prefer a one-liner in the terminal, use:

cp -r ~/.local/share/klipper/ /path/to/backup/

Automating the Backup with Cron

To back up automatically every hour, you can add a cron job. Open your crontab with crontab -e and add a line like:

0 * * * * cp -r ~/.local/share/klipper/ ~/backups/klipper/

This copies the folder every hour on the hour. The -r flag ensures the directory is copied recursively. You can adjust the schedule (e.g., */30 * * * * for every 30 minutes).

One caveat: if Klipper is running, the file might be momentarily inconsistent. To avoid that, you can use rsync which handles partial writes better:

0 * * * * rsync -a ~/.local/share/klipper/ ~/backups/klipper/

Restoring the Clipboard History

To restore a backup, simply replace the current ~/.local/share/klipper/ folder with your backup. Again, quit Klipper first:

  1. Quit Klipper from the system tray.
  2. Rename the current folder: mv ~/.local/share/klipper ~/.local/share/klipper.bak
  3. Copy your backup into place: cp -r /path/to/backup/klipper ~/.local/share/
  4. Start Klipper again.

When Klipper starts, it reads the history file and populates its menu with the restored entries. Note that any items you copied after the backup will be lost, so restore only when you are sure you want to roll back.

Using a File-Syncing Service as a Live Backup

Instead of cron, you can use a cloud sync client (like Nextcloud, Dropbox, or Syncthing) to sync the ~/.local/share/klipper/ folder to another device. This gives you near-real-time backup without writing a script.

To do this, add the folder as a synced folder in your client of choice. The client will watch for changes and upload them. This is the most convenient option for most users because it requires no maintenance.

One downside: the history file can grow large if you copy a lot of text. If it gets huge, you might want to clear the history periodically (right-click Klipper → History → Clear History) to keep the sync fast.

Common Problems and Solutions

Problem: The history file is empty after restore. This usually happens because Klipper was still running when you copied the file, and it overwrote your restored version on exit. Always quit Klipper before restoring.

Problem: The backup is missing recent items. If you use cron, the last hour of copies might be missing. Schedule the backup more frequently (e.g., every 5 minutes) or use a sync service.

Problem: The file is locked. If you get a “Text file busy� error when copying, Klipper is writing to the file. Wait a moment and retry, or quit Klipper.

Frequently Asked Questions

Can I export the clipboard history as a plain text file? The history file itself is plain text, so you can just copy it. However, it may contain binary data if you copied images or other non-text content, which can make it messy to read.

Does Klipper have a built-in export/import feature? No, Klipper does not have a menu option to export or import history. You have to manage the file manually.

Will backing up the history file also back up my images? Yes, if you copy images, they are stored in the history file as base64-encoded data. The file size will be larger, but the backup will include them.

Is there a way to back up only the last N items? Not directly. You can use a script to read the file and keep only the last N lines, but that is more advanced. A simple full backup is easier.

Can I use a symlink to keep my history on a different drive? Yes, you can move the folder to another drive and create a symlink at ~/.local/share/klipper pointing to it. This way the history is automatically stored on the other drive, which can be a form of backup if that drive is separate.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →