Add secure delete/shred to Dolphin right click menu

Plasma 6.5.5 on Bazzite 43

I am attempting to follow these instructions:

  1. Create file shred.desktop with this content:

    [Desktop Entry]
    Type=Service
    ServiceTypes=KonqPopupMenu/Plugin
    MimeType=all/allfiles;
    Actions=Shred
    #X-KDE-Submenu=Shred

    [Desktop Action Shred]
    Name=Safe Remove
    Icon=edit-delete-shred
    Exec=/bin/bash -c ‘kdialog --title “Safe Delete” --warningcontinuecancel “Safe Delete: Are you sure?” && shred -u -f -z -n3 %u’

  2. Create file shred_folder.desktop with this content:

[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=inode/directory;
Actions=Shred
#X-KDE-Submenu=Shred

[Desktop Action Shred]
Name=Safe Folder Remove
Icon=edit-delete-shred
Exec=/bin/bash -c 'kdialog --title "Safe Delete" --warningcontinuecancel "Safe Delete: Are you sure?" && find %u -type f -exec shred -u -f -z -n3 {} \; && rmdir %u'

  1. Put these files here: /usr/share/kservices5/ServiceMenus/

  2. Reboot (or restart session)

There’s some confusion on my part regarding whether the path referenced in the linked discussion is still accurate. I’m also not clear on how to add files to the folder since I cannot drag them there or save them there without getting a permissions error.

I’m also open to alternative, easier ways to add shredding functionality to Dolphin.

It looks like the instructions you are following are for Plasma 5 (indicated by the /usr/share/kservices5/ path), but since you are on Plasma 6, the system for Dolphin service menus has changed. This version mismatch is likely why you’re encountering issues.

Additionally, because Bazzite is an atomic/immutable operating system, the /usr directory is read-only by design, which is why you’re seeing those permission errors when trying to save files there; they’ll need to go in ~/.local instead.

2 Likes

I wondered if the immutable/atomic nature of Bazzite was the cause of the permissions issue. Is ~/.local/share/Dolphin the relevant folder? I don’t see a ServiceMenus folder in any of its subfolders.

1 Like

I’m not entirely sure what the exact solution would be, but I could look into it if you would like. Here is what Google Gemini has to say (so take this with a grain of salt):

Since you are on Plasma 6 and using Bazzite, the file structure and permissions have indeed changed. The folder you are looking for is not under ~/.local/share/Dolphin.

In Plasma 6, the system for service menus has been updated, and because Bazzite is an atomic/immutable OS, you must use your home directory for these customizations.

1. The Correct Path

The relevant folder for user-level service menus in Plasma 6 is:

~/.local/share/kio/servicemenus/

If this folder doesn’t exist, you can create it by running this command in your terminal:

Bash

mkdir -p ~/.local/share/kio/servicemenus

2. Create the Desktop Files

Since you cannot save to /usr/share/, create the files directly in your local folder. You can use a text editor like Kate or run these commands to create them:

For individual files (shred.desktop):

Ini, TOML

[Desktop Entry]
Type=Service
MimeType=all/allfiles;
Actions=Shred

[Desktop Action Shred]
Name=Safe Remove
Icon=edit-delete-shred
Exec=/bin/bash -c 'kdialog --title "Safe Delete" --warningcontinuecancel "Safe Delete: Are you sure?" && shred -u -f -z -n3 %u'

For folders (shred_folder.desktop):

Ini, TOML

[Desktop Entry]
Type=Service
MimeType=inode/directory;
Actions=Shred

[Desktop Action Shred]
Name=Safe Folder Remove
Icon=edit-delete-shred
Exec=/bin/bash -c 'kdialog --title "Safe Delete" --warningcontinuecancel "Safe Delete: Are you sure?" && find %u -type f -exec shred -u -f -z -n3 {} \; && rmdir %u'

3. Make Files Executable

For security reasons, Plasma 6 requires service menu files in local directories to be marked as executable to function. Run this in your terminal:

Bash

chmod +x ~/.local/share/kio/servicemenus/shred*.desktop

4. Refresh Dolphin

You usually don’t need to reboot. Just close and restart Dolphin. If the “Safe Remove” option doesn’t appear immediately in the right-click menu, check Settings > Configure Dolphin > Context Menu to see if it’s listed and enabled there.

For more details on how these menus work in the latest version, you can refer to the KDE Developer documentation for Service Menus.

After using chmod the Safe Remove option does appear in the right-click menu and generates the confirmation prompt when selected, but it doesn’t actually remove the files or folders. Is there a log I could check to see what’s going wrong?

Yes, there is! In KDE Plasma and systemd-based distributions, applications and the custom scripts they launch via .desktop files log their output and errors to the systemd user journal.

If the shred command in the custom bash script is failing or encountering permission issues, its error messages will be recorded there.

You can check these logs by opening your terminal and running:

journalctl --user -f

This command will “follow” the log in real-time. Once it is running, go back to Dolphin, try using the “Safe Remove” right-click option on a file, and then check the terminal to see exactly what error is being generated.

(Note: You can press Ctrl+C in the terminal to stop viewing the live log when you are done).

F4

:kiss_mark: KISS

I’ve discovered that the new context menu entry works on some files but not others. It seems it can’t handle spaces in filenames. This is the result if I try to delete a file called Text file.txt

Mar 09 12:55:16 pandaneo systemd[2729]: Started app-shred@fd7c5a64585943948aaff2bdce557073.service - shred.
Mar 09 12:55:18 pandaneo bash[1029121]: shred: /run/media/user/storage/r18/litrachor/text: failed to open for writing: No such file or directory
Mar 09 12:55:18 pandaneo bash[1029121]: shred: file.txt: failed to open for writing: No such file or directory
Mar 09 12:55:18 pandaneo systemd[2729]: app-shred@fd7c5a64585943948aaff2bdce557073.service: Main process exited, code=exited, status=1/FAILURE
Mar 09 12:55:18 pandaneo systemd[2729]: app-shred@fd7c5a64585943948aaff2bdce557073.service: Failed with result ‘exit-code’.

Renaming the file to remove the space and trying again works just fine. How do I edit the command to handle spaces?

The command seems to be

shred -u -f -z -n3 %u’

In class till 12:50 PST. I’ll get back to you asap.

You probably need to add double quotes around the %u argument, something like

shred -u -f -z -n3 “%u”’

For such a composed command sequence I would suggest a simple wrapper script that can be directly executed instead of passing everything as an argument to bash -c

1 Like

@krake, this is the right answer for sure. @weatherwax, that exec line has no way of injecting escape sequences into your file name to tell the shell “ignore the space after me.” You need to wrap the shell variable %u in double quotes so it looks like "%u”, then bash will know the space is part of the file name and not an additional command, flag, etc.