Assign executation permission for a bash script file

by Daniel Pham
Published: Updated:
This entry is part 5 of 6 in the series Writing your first script

In this article, we will learn step 2 that is to assign execution permission for a bash script file. In the previous article, you did step 1 of 3 steps to write a bash script file. That is to write a simple script file.

The chmod command is in Linux

The chmod command in Linux is used to assign permissions to files or directories. You can find out more about the chmod command in the Linux Commands category of this blog.

Limited to this article, I will only say how to use chmod to assign permission to a bash script file.

The chmod command syntax is quite simple as shown below:

chmod [permission] file/folder

Assign execution permission to a bash script file

To make an executable bash script file, use one of the following 3 commands, for example I use hello_world script file in the previous article:

chmod a+x hello_world

chmod 755 hello_world

chmod 700 hello_world
assign executation permission for a bash script file
“hello_world” script file before and after assigning executable permission to it.

You see the image above, you will see the file hello_world has changed after running the chmod command. At the very least, you can see the file name changes from white to green. On Linux systems, green is displayed for files or directories with executable permission.

So why are there three chmod commands for a script file? When you look up the syntax for using the chmod command, you can see [permission]. This permission can be used with numbers or letters, you will learn more about these numbers in another article.

In this article, you understand the first and second commands are the same for permissions. It allows everyone to execute that script, remember that on a system that not only has one user, there may be many other users. When using the first and second chmod commands, you allow everyone to use that script.

As for the third chmod command, it assigns execution permission to the file, but only you (the owner) can execute that script. That is the difference between the commands.

So you’ve learned the 2nd step in 3 steps to write a first script, continue with the next article.

(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).

0 0 votes
Article Rating
Series Navigation«« Previous part: Format of a bash script fileNext part: Script file location and execute script »»

You may also like

Notify of
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.



Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 – All rights reserved.

Please write sources “” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Would love your thoughts, please comment.x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.