How to make an icon to enter terminal commands
Let me start by saying that I'm very new to Ubuntu in general, so I realize this may be a basic question. I'm using xubuntu 14.04. I recently got a wireless usb working by following the steps here.
The instructions say that anytime the kernel updates, I must recompile by entering the following into the terminal:
cd ~/mt7601/src
make clean
make
sudo make install
sudo modprobe mt7601Usta
I'd like to know if there's anyway to create an icon on my desktop that I can just double click that will have the effect of entering the above commands into the terminal?
How to create an icon on your desktop to perform the recompile-job
-
Open gedit, paste the lines below into the file:
[Desktop Entry] Name=Recompile Exec=/bin/bash -c "cd ~/mt7601/src&&make clean&&make&&sudo make install&&sudo modprobe mt7601Usta" Type=Application Terminal=true
Save the file as
recompile.desktop
on your desktop-
Make the file executable by the command:
chmod +x /path/to/recompile.desktop
After you made it executable, a generic icon will show up on the file (not necessarily the same as in the image, depending on your icon theme).
-
Simply double click on the file to run it. it will open a terminal window and ask for your password to run the
sudo
part of the command:
Explanation
-
Desktop files (with the extension
.desktop
) can be used to perform all kinds of applications or tasks. To make it run shell commands, the format is:Exec=/bin/bash -c "<command>"
In this case, in the
Exec=
-line, the commands mentioned in your question are separated by&&
, which is effectively the same as placing each command on a new line.This makes it unnecessary to create a separate script; all is included in one launcher.
-
To make a
.desktop
file run from your desktop, you have to make it executable.
After you made it executable, the name as it appears on your desktop is the name, defined in the line:Name=Recompile
-
The line:
Terminal=true
makes the command(s) run in a terminal window.
-
The example file is a very basic one. If you'd like the file to have another icon than the generic one, add a line (e.g.):
Icon=/path/to/icon.png
More on .desktop
files and their required/optional entries here.
You can make a script that can do these commands for you. Simply create a text file located on your desktop that contains the following.
#!/bin/bash
cd ~/mt7601/src
make clean
make
make install
modprobe mt7601Usta
Save it to the desktop as kernelupdate.sh You should then open up a terminal and run the followings commands
cd ~/Desktop/
chmod +x kernelupdate.sh
The script is now executable. You can execute it via the terminal using the following commands:
cd ~/Desktop
sudo ./kernelupdate.sh
Here is the link to a related question that explains how to make it executable via clicking on the icon. How to execute sh script from a desktop shortcut?