Linux chmod FAQ: Can you share an example of how to make a shell script executable with the Unix/Linux chmod command?
A lot of times in the web world you're given a Perl script by someone, and they say, "Put this script on your server, make it executable, and yada yada yada." Skipping the yada-yada part, some times people gloss over the "Make this file executable" part. So, here's a quick lesson of how to use the Linux chmod command to make a Perl script (or any Unix file) executable.
If you have ssh or telnet access to your server, just log in to your server, move to the directory where your file is located (using the cd command), and then run the Unix/Linux
For instance, let's say you have a Perl script named
runme.cgi, and it's located in a directory named
/web/sites/www.example.com/cgi-bin. First, move to that directory with the
cd command, like this:
Then make the Perl script executable by running this chmod command:
chmod +x runme.cgi
After running this chmod command, if you'll then run the
ls command on that file, you should see it has execute permissions, like this:
ls -l runme.cgi -rwxr-xr-x 1 myusername mygroup 1,000 May 19 18:07 runme.cgi
I'm not going to get into all the details here, other than to say that if you see those
x's in the first ten columns of your listing, your Perl script now has the execute permission it needs.
There are other ways of issuing the Linux
chmod command, and I'll show you a few ways here that are roughly equivalent to the
chmod +x command shown above.
Before I show these other options, it's good to know that the
+x option shown above says, "Whatever the file permission is, add the execute bit to it, for the owner, the owner's group, and all others." (That's what we did in the chmod example above.)
The following Linux chmod command says, "Make this file readable, writeable, and executable by the owner and the owner's group; and make it readable and executable by all others":
chmod 775 runme.cgi
This next chmod command is pretty wide open, and can be read as, "Make this file readable, writeable, and executable everyone":
chmod 777 runme.cgi
If you don't have ssh or telnet access to your server, you can often perform this same chmod command functionality using your FTP client. For instance, this chmod capability is supported with FileZilla, and I'll briefly describe how this works with FileZilla:
Here's the image of my FileZilla permissions dialog:
I hope this Linux chmod tutorial has been helpful. For more information on the chmod command, I've also posted an online copy of the Linux chmod command man page out here. Also, to learn more about what those Linux file permission characters (the -rwxr-xr-x characters) mean, take a look at this Linux ls command example page, and this Understanding Linux ls command output page.