9 views

To provide execute permission to the user

chmod u+x this will provide execute permission for the file owner

chmod u+x script.sh

Let us explore this with an example, we have a shell script named powerscript.sh

[askdevops@testserver mydir]$ ls -ltr
total 4
-rw-rw-r--. 1 askdevops askdevops 1 Jun 12 19:02 powerscript.sh
# Permission 664

The incorrect way of changing permission for executing

[askdevops@testserver mydir]$ chmod 777 powerscript.sh
[askdevops@testserver mydir]$ ls -ltr
total 4
-rwxrwxrwx. 1 askdevops askdevops 1 Jun 12 19:02 powerscript.sh
[askdevops@testserver mydir]$

Well!
The script is executable now, however, it can be executed/modified or even deleted by anybody.

Let us revert the permission back to its original state.

[askdevops@testserver mydir]$ chmod 664 powerscript.sh
[askdevops@testserver mydir]$ ls -ltr
total 4
-rw-rw-r--. 1 askdevops askdevops 1 Jun 12 19:02 powerscript.sh

Correct way of giving executable permission:

[askdevops@testserver mydir]$ chmod u+x powerscript.sh
[askdevops@testserver mydir]$ ls -ltr
total 4
-rwxrw-r--. 1 askdevops askdevops 1 Jun 12 19:02 powerscript.sh

# Note the x
# Permission became 764

With this, only owner of the file can execute it!

To provide execute(x) permission for all users, use chmod +x

chmod +x devops.sh

More Examples:

Before changing permission

$ ls -l devops.sh
-rw-rw-r-- 1 developer   developer       275 Aug 15 15:24 devops.sh

After changing mermission

$ chmod +x devops.sh
$ ls -l devops.sh
-rwxrwxr-x 1 developer   developer       275 Aug 15 15:24 devops.sh
Jul 20, 2010 by | 9 views
Articles for DevOps Geeks
MobaXterm Customization
CHMOD Explained!
Bash history powerful tips
Ubuntu bash from Windows
..