mixalbl4
mixalbl4

Reputation: 3945

How to add shred to KDE context menu for safe deletion of file/folder?

How to add the shred utility to the context menu in Dolphin (Linux Mint 18 KDE) for removing files and folders?

Upvotes: 2

Views: 1901

Answers (2)

Dino
Dino

Reputation: 21

This is a slightly changed version that implements a confirmation dialog and a more appropriate icon (imho)

  • Files
[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'
  • Directories
[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'

Upvotes: 2

mixalbl4
mixalbl4

Reputation: 3945

  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
Name[ru]=Удалить навсегда
Icon=trash-empty
Exec=shred -u -f -z -n3 %u
  1. 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
Name[ru]=Удалить папку навсегда
Icon=trash-empty
Exec=find %u -type f -exec shred -u -f -z -n3 {} \;
#Exec=find %u -type f -exec notify-send {} '' \;
  1. Put these files here: /usr/share/kservices5/ServiceMenus/ (how to find this path?)
  2. Reboot (or restart session)

Result:

result

Additional info:

  1. MimeType for files is all/allfiles, for folders it's inode/directory
  2. Used shred options:
-u  - After shredding a file, deallocate it (if possible) and then remove it.
-f  - Change permissions to allow writing if necessary.
-z  - Add a final overwrite with zeros to hide shredding.
-n3 - Use 3 passes of overwriting.
%u  - The file path for removing.
  1. Specifics for removing a folder with shred: https://unix.stackexchange.com/a/27029/330017
  2. Here's more on creating context menu entries: KDE documentation

Upvotes: 1

Related Questions