Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to create desktop shortcut, that would do as follows:

  1. open Terminal
  2. change directory
  3. make a command inside that directory
  4. type password (sudo)

I tried with Terminal profiles, but I didn't find option for 2. and 4.

share|improve this question
up vote 1 down vote accepted

First you need a script like one from the following example:


commands () {
    cd / # change directory, in this case to `/`
    echo "your_password" | sudo -S mkdir -p "test" # execute a command as root for which the password is automatically filled
    $SHELL # keep the terminal open after the previous commands are executed

export -f commands

gnome-terminal -e "bash -c 'commands'"

Don't forget to make the script executable!

Then, if you are not familiar about how to execute a script using a desktop shortcut, see Execute sh script from *.desktop file?.

share|improve this answer
Thank you, but I think I need some more help. Do I type this script in terminal or make a document (with .sh ending)? Do I start with #!/bin/bash? Do I type password with or without ""? What about "test" in the echo line - it's marked red, do i have to insert something else there? Same question with "bash -c 'commands'"? Where do I type my actual command, that will be executed? – Mersault Jan 14 '14 at 13:05
Use a text editor. Include '#/bin/bash' - won't work without! No password necessary - you created the file. Don't worry about the red. You need to insert your own code where it says 'sudo -S mkdir -p "test"'. Read the links for how to make it executable and how to run from desktop. – comrademike Jan 14 '14 at 13:24
I almost made it:) executes the command, but I still have to type my root password...where in a script I put my password? I tried after echo (with or without ") and it doesn't work... – Mersault Jan 14 '14 at 16:11
@mo echo "your_password" - replace your_password with your password; keep quotes and your password shouldn't contain another quotes. This command: mkdir -p "test" will create a directory called test in / if there doesn't exist another one with the same name; it's just an example and you can change the command as you wish. – Radu Rădeanu Jan 14 '14 at 16:50
I did that, but it doesn't starts Terminal, but it wants my sudo password...when I type it, then the command is executed. – Mersault Jan 14 '14 at 17:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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