Ubuntu -- Nautilus 脚本不会 运行 "srm" 安全擦除文件

Ubuntu -- Nautilus scripts won't run "srm" to securely wipe file

我正在尝试向 Nautilus 添加一个上下文菜单选项,这样当我右键单击一个文件时,我可以选择 运行 srm 来安全地覆盖它用零而不是将它移动到 /Trash 或 rm'ing 它。我在 ~/.local/share/nautilus/scripts

中有以下可执行文件
#!/bin/bash

#Make local Nautilus filepath variable global
export srmthis=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS

#Copy the above variable to a log
echo "$srmthis" >> logfile.txt

#Now, please srm secure-delete the file indicated in the filepath
sudo -E /usr/bin/srm -flz "$srmthis"

$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS 是在其中选择文件时由 Nautilus 设置的变量。我的想法是,我会把它放到我自己的变量 $srmthis 中,然后将它传递给 srm 作为目标文件,选项为 "-flz" 用于更快但更不安全的擦除。

但是没用。没有输出,没有弹出警告。

当我 echo "$filetosrm" >> somefile.txt 时,我确实得到了一个输出,所以我知道变量已设置。我也可以在终端中单独使用 srm 没问题。

我做错了什么?

非常感谢!

P.S。尝试 运行ning srm 与 gksu、pkexec、| xargs 等无济于事。

想通了。这是有效的新代码:

#!/bin/bash

#Make local Nautilus filepath variable global
srmthis=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS

#Copy the above variable to a log
echo "$srmthis" >> srmtemp.txt

#Get the first line from temp file to get rid of annoying newline
line=$(head -n1 srmtemp.txt)

#Wipe the file with srm: -fllz fast mode, -r recursively for any subdirectories
/usr/bin/srm -fllzr "$line"

#Clean up
/usr/bin/srm -l srmtemp.txt

此外,我没有使用 sudo /usr/bin/srm,而是在我的 /etc/sudoers 中添加了 srm 作为我的用户名 whiterabbit ALL = (root) NOPASSWD: /usr/bin/srm,这允许它 运行 没有必须在脚本中包含命令 sudo

这会将 srm 添加为 Nautilus 脚本。我现在可以右键单击一个文件,然后转到 Scripts -> SRM 并在 GUI 中用零擦除文件,而不是 rm'ing 或将其移动到垃圾桶。