Archive for October, 2009

How to Run a Shell Script as Superuser

Sunday, October 4th, 2009

If you've ever tried to run a shell script as superuser in Linux by using the syntax sudo ./example-shell-script, you'll know that doesn't work. Instead, this is how you need to do it:

  1. Create your script
    vi example-shell-script
  2. Change the permissions
    chmod 755 example-shell-script
  3. Switch into superuser mode
    sudo su -
  4. Run the script
    ./example-shell-script
  5. Log out of superuser mode
    exit

Copyright © 2010, Ink Plant. All rights reserved.