I have created this alias to replace rm
with gio trash
...
alias rm='function move2trash(){
if hash gio &> /dev/null; then
gio trash "$@" && \
echo "File(s) moved to trash instead." && \
echo "See \`man gio\` for more information."
else
echo "Removing file(s) is a bad habbit, instead you should move or rename them."
echo "If you really have to remove some thing(s) you can use the full path i.e. \`/bin/rm\`."
fi
}; move2trash'
But files get lost when running sudo
in front of it ...
[~] touch test.file
[~] sudo rm test.file
[~] sudo ls /root/.local/share/Trash/files/test.file
/root/.local/share/Trash/files/test.file
[~] touch test.file2
[~] sudo rm test.file2
[~] sudo ls /root/.local/share/Trash/files/test.file2
ls: cannot access '/root/.local/share/Trash/files/test.file2': No such file or directory
[~, ERR:2]
Also I get errors when running options or variables with rm
...
[~] touch test.file3
[~] LC_ALL=C rm test.file3
bash: Syntaxfehler beim unerwarteten Symbol »(«
[~, ERR:2] rm -i test.file3
gio: Unbekannte Option -i
Aufruf:
gio trash [OPTION …] [ORT…]
Dateien oder Ordner in den Papierkorb verschieben/wiederherstellen.
Optionen:
-f, --force Nicht vorhandene Dateien ignorieren und niemals nachfragen
--empty Den Papierkorb leeren
--list Dateien im Papierkorb mit ihren ursprünglichen Orten auflisten
--restore Eine Datei aus dem Papierkorb am ursprünglichen Ort wiederherstellen (erstellt unter Umständen wieder den Ordner)
Hinweis: Wenn der ursprüngliche Ort der gelöschten Datei bereits existiert, wird er mit der Option »--restore« nicht überschrieben, außer »--force« ist gesetzt.
Hope you guys have some advice to make this alias more reliable,
or at least explain to me why this alias doesn't work with sudo
and how to remove options.