Setting up permissions on a script

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to: navigation, search
← Shell CommentsHomeExecute a script →

The chmod command (change mode) is a shell command in Linux. It can change file system modes of files and directories. The modes include permissions and special modes. Each shell script must have the execute permission. Mode can be either a symbolic representation of changes to make, or an octal number representing the bit pattern for the new mode bits.

Examples

Allowing everyone to execute the script, enter:

chmod +x script.sh

OR

chmod 0755 script.sh

Only allow owner to execute the script, enter:

chmod 0700 script.sh

OR

chmod u=rwx,go= script.sh

OR

chmod u+x script.sh

To view the permissions, use:

ls -l script.sh

Set the permissions for the user and the group to read and execute only (no write permission), enter:

chmod ug=rx script.sh

Remove read and execute permission for the group and user, enter:

chmod ug= script.sh

More about chmod

Type the following command to read chmod man page:

man chmod

Please note that script must have both executable and read permission.

External links

← Shell CommentsHomeExecute a script →