I've created a script to empty my trash. I want to be able to execute it without having to use the terminal. Is there anyway I could do this?
1 Answers
A nice way to execute scripts by double clicking them is to make a .desktop
file, which is essentially a shortcut. Aside from scripts, it can execute pretty much any executable, including .jar
. Here's how to make one:
- Create a file and name it
<program name>.desktop
Open it with GEdit and paste this text in:
[Desktop Entry] Version=1.0 Type=Application Name=<whatever you want the file name to be> Comment=<description of program> Exec=</path/to/script> Icon=</path/to/optional/icon.png>
Edit the Name, Comment, Exec, and Icon fields to what you want. Having an Icon is optional and you can simply remove that line if you don't want to have one. Make sure to delete the surrounding
<>
.Save the file and then go into its properties.
Go to Permissions and mark it as executable.
You should now be able to double click this file and it will execute your script. If you don't want a terminal window to be shown, add Terminal=false
to the file. You can now add this file to the launcher for easy access, if you like. If you want to move your script, you'll have to update the Exec path in the .desktop
file.
Any problems, just comment.
---Update---
Thanks to @kos, I now know the solution to your problem. Instead of having sudo rm -rf ~/.local/share/Trash/*
, you want just rm -rf ~/.local/share/Trash/*
. Since ~/.local/share/Trash
is owned by you, you can do anything from your user account to edit it without sudo
. After testing the non-sudo command out, I can confirm that it works.

- 19,395
- 12
- 50
- 65
-
It says there was an error launching the application.[Desktop Entry] Version=1.0 Type=Application Name=
Comment= – draoi Nov 17 '15 at 00:02Exec=<./empty_trash.sh> Icon=</path/to/optional/icon.png> -
-
A window comes up and says "There was an error launching the application." – draoi Nov 17 '15 at 00:04
-
-
-
-
-
-
[Desktop Entry] Version=1.0 Type=Application Name=
Comment= – draoi Nov 17 '15 at 00:07Exec=<./empty_trash.sh> Icon=</path/to/optional/icon.png> -
Yeah, take away the
<>
from around the paths, name and comment. Those were to denote that what was inside should be changed. – TheWanderer Nov 17 '15 at 00:08 -
-
-
Under
Exec
you can't have./
since that's the working directory. If the script is in your home directory, change that to~/
, although a definite path might be better. – TheWanderer Nov 17 '15 at 00:11 -
-
-
-
Add
Terminal=true
to it and see what happens. What's the command that you're running? – TheWanderer Nov 17 '15 at 00:18 -
-
-
So you double-clicked the desktop file but nothing happened (the trash didn't empty)? I would say just add the command to the Exec field. You'll have to enter your password when you double click it. – TheWanderer Nov 17 '15 at 00:20
-
The trash doesn't empty, and the terminal doesn't open for me to enter my password. Clicking on the script itself works, but naturally it would be nicer to get it working with a .desktop icon. – draoi Nov 17 '15 at 00:22
-
-
[Desktop Entry] Version=1.0 Type=Application Name=trashx Exec=sudo rm -rf ~/.local/share/Trash/* Terminal=True – draoi Nov 17 '15 at 00:23
-
-
Now that causes the error message to pop back up. I've got to go to sleep now, but this has been interesting. I'm going to look into this further when I have more energy. I like the idea I've being able to make a desktop icon for a little script, also so that I could run other programs that I usually have to start with the terminal. – draoi Nov 17 '15 at 00:30
-
It is a great feature. I'll reboot into Ubuntu in a bit and update my answer if I'm able to come up with anything. – TheWanderer Nov 17 '15 at 00:35
-
Thanks to @kos, I now know that
sudo
is unnecessary for this command. Puttingrm -rf ~/.local/share/Trash
instead fixed it. – TheWanderer Nov 17 '15 at 00:49 -
As a .desktop file, it's still not working. As an sh file, it works without the sudo command. However I'm afraid that if I delete a locked file, it will only work with the sudo command. – draoi Nov 18 '15 at 09:34
-
The original problem was that the normal method of emptying the trash did not work after I had deleted a large folder, possibly because it was locked. http://askubuntu.com/questions/698920/ubuntus-terrible-trash/698922?noredirect=1#comment1023841_698922 – draoi Nov 18 '15 at 09:37
-
It's kind of dangerous, but what if you put a
chmod 777
on the stuff inside the Trash folder before you run the delete command. – TheWanderer Nov 18 '15 at 11:01
chmod +x <path/to/script>
, if not done already. Then you will be asked whether to run the script when double clicking it, at least in Nautilus. But where's the point, when you can simply right click on your trash and tell it to empty itself? – s3lph Nov 16 '15 at 23:34