Gordan Jandreoski

Gordan Jandreoski

var blog = { "dev", "cloud", "tech", "geek", null};

Newsletter Subscribe


How to create executable bash script in Ubuntu

Gordan JandreoskiGordan Jandreoski

Linux tips and tricks

Very often I find my self doing repeating tasks when working with DevOps operations; so I always think how to automate things. When working on Windows platform I tend to create PowerShell scripts on Linux I create bash scripts.

On Ubuntu it is very easy to create executable scripts that will hold your bash commands. To create executable bash script create new file with your favorite text editor; mine is nano :-).

nano script.sh

In the new file reference the script interpreter at the beginning of the script


Next add your commands and save your file. Just for illustration; here is a simple automation script I use when deploying web sites. This commands will recursively copy all files for ~/www to the target /var/www/html folder and will change permission to all files to the www-data group.

rsync -r ~/www/* /var/www/html/
chown -R www-data:www-data /var/www/html

At the end change the permissions to your file to make it executable

chmod +x script.sh

To execute the script type


That is it. Enjoy coding! For more info check:

  • [http://www.gnu.org/software/bash/](http://www.gnu.org/software/bash/)
  • [https://en.wikipedia.org/wiki/Unix_shell](https://en.wikipedia.org/wiki/Unix_shell)