1

I'm looking for help creating a shortcut to open the terminal and run

sudo apt-get update -y && sudo apt-get dist-upgrade -y && sudo apt-get autoremove -y

I'd like to see the terminal and the progress the update is making if possible.

I know I can create a cron job or set up "Unattended-upgrades" but i'd like to execute the command myself and a desktop shortcut seems ideal.

So far I have created a blank file with this code:

[Desktop Entry]
Version=1.0
Name=Update
Comment=Test the terminal running a command inside it
Exec=bash 'sudo apt-get update -y && sudo apt-get dist-upgrade -y && sudo apt-get autoremove -y'
Icon=utilities-terminal
Terminal=True
Type=Application
Categories=Application;

All that seems to happen though is the cursor spins for a while and I don't know if it has actually run the command.

Thanks

10
  • have you looked at any task manager if it's actually running? You can tell that it is based on the network activity (LAN port lights flashing) and disk activity (yellow light flashing rapidly/continuously)
    – Aloha
    Commented Jun 30, 2016 at 15:46
  • I've ran it a few times now with the task manager open and there is no extra usage in ram or cpu. The ethernet switch on my desktop doesnt blink anymore than it is doing normally so I would say it isnt running the command.
    – Tabias
    Commented Jun 30, 2016 at 15:51
  • Did you make the file executable?
    – Aloha
    Commented Jun 30, 2016 at 15:55
  • not too sure tbh. all i did to create the file I've outlined above.
    – Tabias
    Commented Jun 30, 2016 at 15:56
  • sudo chmod +x /path/to/your/file
    – Aloha
    Commented Jun 30, 2016 at 16:18

2 Answers 2

1

I would create a file called update.sh then right click on the file and go to properties. In there you will see a property called "Allow executing file as program" Check that tick box and save. Now upon double clicking on the file it will now ask you to open it in the terminal and I believe your problem will now be solved.

Goodluck

2
  • I followed these instructions and added the line from above edited with PandaLion98 and Scruss's suggestions and it works. It prompts me to open in terminal but other than that it does everything I want it to. Thanks everyone!!
    – Tabias
    Commented Jul 1, 2016 at 11:45
  • Anything more complicated than just pointing to a script can be problematic in shortcuts.
    – SDsolar
    Commented May 23, 2018 at 15:08
0

Your problem is with the Exec line. bash 'command' is not a valid way to execute a command with bash, you want bash -c 'command'. However the exec line already uses a shell to execute the command so you do not need bash wrapper at all and can just use:

Exec=sudo apt-get update -y && sudo apt-get dist-upgrade -y && sudo apt-get autoremove -y

Note that you might find that the terminal window closes right after the last command finishes. If you want to keep it open you can add (depending on your terminal)

TerminalOptions=--hold or TerminalOptions=--noclose (depending on the terminal application you use).

Alternative you can append ; read to the end of the command to keep the terminal window open waiting for some input. This will work even if your terminal does not support an option to keep it open.

Exec=sudo apt-get update -y && sudo apt-get dist-upgrade -y && sudo apt-get autoremove -y; read

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.