Setting the File Permissions
Once you have a shell script created as a text file containing valid commands, you must set the file permissions on that text file so that UNIX can execute the script.
UNIX file permissions are divided into Read, Write, and Execute permission for the owner of a file, the group the owner belongs to, and all other users on the system. Before you can execute a script, you must at least activate the Execute permission option for the owner of the file (thats you). If you want other users on the UNIX system to have permission to execute the script, you can activate the group or other Execute permission. Even the i>UNIX root user (superuser)) cannot execute a script until the Execute permission option has been set.
Until then, UNIX simply does not recognize the file as something that can be run.
- Execute permission: A file permission within UNIX file systems that allows a program to be launched or executed.
- UNIX root user: The administrative account on a UNIX system; the superuser who has all access to the system.
To view the permissions of your script file, use the
ls command with the
-l option. The set of letters on the left side of the line shows the file permissions, three for the owner, three for users in your group, and three for other users on the system.
If all of these were set, you would see
rwxrwxrwx. This is what you will see if you are using your DistributedNetworks Labs
account (the file size, owner name, and date will differ, of course, but notice the permissions on the left side of the line):
% ls -l welcome
rw-r—r-- 1 nwells students 13 Sep 2 16:39
To set or change the file permissions on your script file so they include the Execute permission option., use the
In the following example, the parameter u refers to the user, or owner of the file. x refers to the Execute permission. The command looks like this:
% chmod u+x welcome
You can also set the Execute permission for the group or others by adding a g or an o, respectively. To set the permission for all three, the command would look like this:
% chmod ugo+x welcome
Or, if you prefer the abbreviated version, you can use the letter a, for all (user, group, and other).
% chmod a+x welcome
File Permissions - Exercise
Click on the Exercise link below to try setting up correct file permissions in your UNIX Labs account.
Setting File Permissions - Exercise
With the file permissions set, you are ready to run your script in the next lesson.