How To Run the .sh File Shell Script In Linux / UNIX

Ihave downloaded software for my Linux or Unix-like system from the Internet. There is a file called How do I run an .sh file to install the software in macOS? How do your run .sh files from command line?

You can open or run .sh file in the terminal on Linux or Unix-like system. The .sh file is nothing but the shell script to install given application or to perform other tasks under Linux and UNIX like operating systems. The easiest way to run .sh shell script in Linux or UNIX is to type the following commands. Open the terminal (your shell prompt) and type the commands.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux or Unix-like systems
Est. reading time 3 mintues

How do I run .sh file shell script in Linux?

The procedure to run the .sh file shell script on Linux is as follows:

  1. Open the Terminal application on Linux or Unix
  2. Create a new script file with .sh extension using a text editor
  3. Write the script file using nano
  4. Set execute permission on your script using chmod command :
    chmod +x
  5. To run your script :
    Another option is as follows to execute shell script:

Let us see script examples and usage in details.
How do I run .sh file shell script on Linux or Unix system?


The syntax is:

How to run .sh file as root user

Some time you need root access to install application; without root, you won’t have the necessary permissions to install application or make system level modifications. Root access is disabled by default on many Linux and UNIX like systems. Simply use the sudo or su command as follows:
sudo bash
Type your password. Another option is to use the su command as follows to become superuser:
su -
Type root user password and finally run your script:

How to use chmod command to run .sh shell script in Linux

Another recommend option is to set an executable permission using the chmod command as follows:
chmod +x
Now your can run your .sh file as follows

How do I run .sh file named

Just run the following two command:
chmod +x

The dot (.) refers to the current working directory. The is in the current directory so you run it as above or as follows too:

GUI method to run .sh file

  1. Select the file using mouse.
  2. Right-click on the file.
  3. Choose Properties:
    How to run .sh file in Linux
  4. Click Permissions tab.
  5. Select Allow executing file as a program:
    How do I run .sh files in Linux or Unix
  6. Now click the file name and you will be prompted. Select “Run in the terminal” and it will get executed in the terminal.

Running .sh file shell script and debugging options

Pass the -x to debug shell script when running on your system. It print commands and their arguments as they are executed. For example:
bash -x
sh -x

Want to show shell input lines as they are read. Try passing the -v option:
bash -v script-name
We can combine both options. In other words, try it as follows:
bash -x -v
For more information see how to improve your bash/sh shell script with ShellCheck lint script analysis tool and other bash debugging hints here.


You learned how to run .sh file shell script using combination of the chomod and dot (.) or sh/bash command. We can use any one of the following command execute shell script on Linux and Unix-like systems:

## or 
chmod +x /path/to/script/file

See the following resources for more info:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 54 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
54 comments… add one
  • lekhraj Oct 1, 2007 @ 7:53

    anybody tell by which coomand i will check the modified date of files/dir in linux o/s

    • sushant suryawanshi Oct 13, 2012 @ 8:14

      date -s “2 OCT 2006 18:00:00”

  • rashid Feb 20, 2008 @ 9:38

    if we want to install software from cd.. how should be the command? i’m the newbie

  • anonomys Dec 19, 2008 @ 21:43

    rashid, if you want to install software from the cd you should try synaptic package handler or apt-get .

    if the software is usually from the cd it will tell you to insert it

  • Black_Ps` Jun 11, 2009 @ 3:31

    How can i execute this command export PS1=”\[[33[01;32m\]\u@\h\[33[01;34m\] \W]\]#” from a .sh script for example and make it work ?


  • J_Art Jun 21, 2009 @ 21:51

    Hey Black_Ps`
    There are a few ways to do this but if you are not familiar with some of the nuances of Linux, it might be easier to create a new folder to place the file in (or all of your scripts in) like home/username/Desktop/scripts (substituting the actual user name in place of username). The following instructions are based on Fedora 10 with GNOME desktop so if you are running a different Linux distro, you may or may not have a few slight variances. Once you have a good place to store your scripts, you can use the GUI to help with creation of the shell script. Next, click on the “Applications” menu and highlight “Accessories” and then select “Text Editor” Type the following command #!/bin/bash and then press the enter key. Now, type the command you listed into the text editor and then select the “Save As” option. Now name your file (highly recommended that you don’t name it with spaces and make the name all lower case to help with ease of use later) and save it to your new folder you created…remember to give it a .sh name extension. Now close the text editor and go back to the “Applications” menu and highlight “System Tools” and then select “Terminal”. Type the following command cd /home/username/Desktop/scripts (again substituting the actual user name in place of username). The command ls and then press the enter key. Did it return the name of your script as a file in that folder? If so, move on to the next step. If it did not, navigate to the folder where you saved this file and move it to the correct folder. Type the following command chmod 755 That’s it, you now have an executable shell script that will execute your command. You can do so by double clicking on it from the GUI, calling it from the terminal like so bash /home/username/Desktop/scripts/ or you could put it on the cron to run unattended if you needed to. I hope this helps some or at least points you in the right direction.

    • kashif Feb 9, 2012 @ 11:53

      can you please expalin it more detailes.

  • Black_Ps` Jun 21, 2009 @ 22:09

    Ok thanks i’ll give it a try

  • shunan Jun 30, 2009 @ 6:17

    When i open the terminal in UNIX..something like interactive keyboard authentication bla.. bla.. is coming..nd its difficult me to go on typing my commands and navigating through the directors and can i fix this..? any idea…? any command? anything helpful will be highly appreciated. _thanks_

  • J_Art Jun 30, 2009 @ 21:52

    Hi shunan

    Is it safe to assume that you have someone in an administrative role who oversees the security of this UNIX terminal? The reason I ask is because this sounds like something I encountered once with something called PAM (Pluggable Authentication Module). It’s a security concept that involves VSHELL. To be perfectly honest, I’m not too familiar with it and the only thing I can vaguely remember about it is that it somehow involves configuring authentication to be controlled by PAM via keyboard-interactive authentication. I realize I didn’t help much here but I hope this at least points you in the right direction. PAM is a product of SUN so you might find something worth while on their page but I haven’t really read up on it so I can’t make any promises. –>

  • Nate Sep 23, 2009 @ 20:06

    This is just straight pissing me off.
    I’ve run the file in the terminal and have gotten to a eula where it asks if I accept and to type yes or no. I type yes and hit enter.
    it said it can’t install it because permission is denied. But a window didn’t pop up to ask for my password.
    I’m about to kick Ubuntu in the face.

  • Dare_devil Dec 2, 2009 @ 22:52

    hi i am newbie too to linux system i’ve a direct question:
    i have arch linux but nothing from these commands work terminal tell me the following:
    command not found
    help me!

  • tugrul Mar 2, 2010 @ 22:25

    if you are using fedora 12 like i am, open up the terminat, switch to the root and with the terminal get on the fileway that you downloaded your .sh file.So write “sh” click on enter and that’s it

  • Gary James Mar 8, 2010 @ 20:50

    Excellent advice. Thanks Gary ( A newly converted Linux enthusiast)

  • dishant Mar 23, 2010 @ 9:16

    can i execute a shell script in another shell script

    • Iqbal Jun 5, 2010 @ 9:28

      Hey all,

      Yes dishant,

      You can run the shell script inside the other.
      But keep in mind that In the second script do not kill the first one.
      If you want to kill the first one, then back up the file name somewhere and kill it, then use that path in the second script.

      Iqbal S.

  • panchotiya jigar r Apr 15, 2010 @ 16:57

    this is the best site of linux information to me
    i learn lots of by this web site
    it’s realy very helpful web site
    i use this website for longtime
    it’s give all answer of your questions
    thanks for help

  • sara Aug 21, 2010 @ 6:11

    in fedora 12 i switch to root by command : su
    and ./ but the error come out: No such file or directory
    i want to know how it detect the folder is inside?

  • sara Aug 21, 2010 @ 6:12

    switch to root with command: su –

  • MikeM Nov 2, 2010 @ 14:12

    So, I have a similar problem as Sara. Created a script, and used “./” prefix to execute it, and received “ksh: ./ not found.”

    If I use “sh” instead of “./” it seems to run fine.
    Permissions of are set to 777.
    I have other scripts that run fine, and some that do not… What am I missing here?

  • pari Feb 28, 2011 @ 4:57

    may be u r not giving the correct path, check ur path again. Firstly reach to ur folder n then switch to root. I know it is very basic thing but sometimes mistake happens in such things also…

  • dave Apr 23, 2011 @ 4:17

    This is hilarious. Came across this site by accident, but just noticed advice to a newbie.

    “Open the terminal (your shell prompt) and type the command:”

    To a newbie, that is still gibberish.

  • nathan Jun 13, 2011 @ 10:08

    nice one for beginners.. good working

  • shin_chan Jul 6, 2011 @ 5:06

    Alright a very nice tutorial….really helpful but I have a little problem…..
    I want to run the .sh in background so that even I can logout.
    I am using the command “nohup sh &” and a file named “nohup.out” is also made but it contains an error which says “no such file or directory”…I am using the command in folder where the .sh file is located.
    Pls tell where I am doing it wrong!!!!

    • Clifford Feb 3, 2012 @ 0:43

      Put the following at the end of the syntax:

      2>&1 &

      I hope this helps!!!

  • sonaht Aug 23, 2011 @ 20:39

    Thanks for this good and clear information. Very helpful for eachothers.. that are beginners :)

  • Areeg Sep 18, 2011 @ 23:59

    in ubunto 11.04
    you need to specify the full path of the file not only th name .sh

  • Dhruv Sep 22, 2011 @ 19:41

    very nice … i need some more article on that particular topics can you please send me some link so that i can check daily

  • kishore Nov 7, 2011 @ 16:36

    i m getting the error output ……The program returned an error code (126)……..
    when i run the sh

  • ashok Mar 1, 2012 @ 8:35

    how to save modified .sh file.Iam trying to install hadoop on my system.But JAVA_HOME path is to be changed from jdk 1.5 to jdk6.i need to modify file.But mysystem is not allowing.please suggest me

  • maxx Mar 11, 2012 @ 7:13

    thanks for the clear information

  • Doug Apr 3, 2012 @ 23:28

    I am trying o run ” ” in my terminal. In several attempts at rooting my phone. Samsung SCH 720 Admire. In the You Tube video ”” the tech describes very fast ” You may need to run chmod or chmod 755” ?? What ever that means.???

    I have googles searched till my fingers blead and eyes tear . This is going on 5 days. I cannot figure this out. Please help.

    My question is. When I am in Terminal– What do I type in order to run the file? Or Chmod 755 the file? Can I simply copy paste the script from the file into Terminal?

    • 🐧 nixCraft Apr 4, 2012 @ 11:11

      Type any one of the following command:

      chmod +x 




  • Hennie Jun 17, 2012 @ 20:30

    thnx for this info noobs like us are always looking for simple clean command lines
    i created a script that cleans/delete logfiles but could not test it
    using the simple bash i could test it
    added the cronjob after that and it all works fine



    echo && date

    if test -f $TARGETDIR_1/$FILE_1 ; then
    echo “XXX.log present!”
    chown $OWNER $TARGETDIR_1/$FILE_1
    rm $TARGETDIR_1/$FILE_1
    echo “No XXX.log present?!?!Nothing to remove”


  • ramchandra deshmukh Oct 29, 2012 @ 7:51

    sir i try script program us but plz explain at commands in details in terminal prompt …

  • balakrishnan Dec 3, 2012 @ 6:21

    i want to include macro in my script file like #define INT int how to use this macro in my script file

  • cat Jan 20, 2013 @ 7:54

    hey guys :)
    i want a script to send data from DB to E-mail automatically

  • Rajesh Sharma Aug 22, 2013 @ 20:18

    Please tell me how to download software from net to run unix command in desktop

  • Ravinder Oct 19, 2013 @ 6:36

    thanks guys. this is really helpful

  • abdul Apr 22, 2014 @ 8:22

    i need to write a shell script that will give read, write and execute permissions to the file owner and group owner of the file

  • Jas Jun 16, 2014 @ 5:32

    Can anybody help me how to schedule below command to run every week on Monday?
    df -h |egrep ‘Filesystem|log|new’ |awk ‘{print $0,”\n”}’ | less | mailx -s “subject”

    Thanks in advance for your help.

  • venkat Apr 30, 2015 @ 16:13

    1) I want create one shell which connects to 4 diffrent servers and executes different shells.

    ex:a) path: DDP1/
    b) path:DDP1/
    c) path:DDP1/
    d) path:DDP1/
    i have general user but i need to connect to sudo also. please any one help me.

  • Stan Aug 12, 2015 @ 7:59

    Thanks for article.
    If i want to run my script “” just like command “up”. What should i do for this? Thanks.

    • 🐧 Vivek Gite Aug 12, 2015 @ 11:23
      mkdir ~/bin/
      cp ~/bin/
      export PATH=$PATH:$HOME/bin/
  • vanya Oct 26, 2015 @ 11:33

    that article helped me =)

  • George Nov 9, 2015 @ 8:36

    Thank you very much !!!

  • WS Feb 28, 2016 @ 17:03

    Muito obrigado por elaborar e compartilhar esse tutorial

  • Chukka Nukka Oct 27, 2016 @ 20:03

    Thank you.

  • s.syedali fathima Feb 17, 2017 @ 8:40

    1. How to install cp -R in linux?

  • bash Aug 30, 2017 @ 19:35

    bash -x
    for debugging

  • रामलाल त्रिवेदी Feb 27, 2021 @ 10:06

    यह बहुत बढ़िया ट्यूटोरियल है. विवेक भाई, कृपया इस तरह के अच्छे काम करते रहें.

  • Chris Cole Apr 18, 2021 @ 14:11

    I am reading this the 5th time and still do not understand a thing. I’m calling my 15 year old daughter to translate…

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum