UNIX commands for Web developers

A quick guide to the essential UNIX commands required for remote maintenance of a Web site.

  • cd
  • ls
  • du
  • exit
  • chmod

cd - change directory

cd - return to root directory
cd .. - up one level in the directory heirarchy
cd cgi-bin - change to a sub-directory of the current directory, called "cgi-bin"


ls - list contents of current directory

ls -a - all files
ls -F - show types
ls -l - show long listing, including access permissions


du - disk usage

du - report disk usage in "blocks" (512 bytes)
du - k - report disk usage in kilobytes


exit - Sever connection with the server


chmod - Change permissions (or "mode") of a file or directory

e.g. chmod 755 animate.cgi - the file "animate.cgi" can be read and executed by anybody and can also be changed by the owner of the file.

A file (or directory) can be readable, writeable, and executable. Permissions to read write and execute can be set separately with local, group-wide, or global scope.

If a permission is local, it refers only to local users (usually the maintainer of the Web site); if a permission is global, it refers to anyone gaining access to a site from anywhere (including the Internet). In general, if a Web site is being maintained by one person using a single user account, access permissions of group-wide and global scope will generally be set to the same value.

The three digits that are used as arguments of the chmod command define the access permissions of the file (or directory) that is entered immediately after them. The first digit defines permissions with local scope; the second, group scope; and the third, global scope.

Read permission is arbitrarily given a value of 4; Write permission has a value of 2; permission to execute is 1, so that a single digit between 0 and 7 uniquely defines the access permissions for a given scope.

0 no permissions;
1 permission to execute;
2 permission to write;
3 permission to write and execute;
4 permission to read;
5 permission to read and execute;
6 permission to read and write;
7 permission to read, write and execute.

For directories, access permissions mean something similar. To gain access to a directory, execute permission is required. To change files, write permission is required. To display a default index file or to list the directory contents if no index file is present, read permission is required.

Here are some common uses of the chmod command:

chmod 711 miscellaneous - make a directory accessible to the world;
chmod 755 root - make the root directory accessible and display the index page;
chmod 777 root - beware of doing this to your root directory;
chmod 644 *.html - make all html documents accessible to the world;
chmod 755 *.pl - make all .pl documents accessible to and executable by the world;
chmod 600 private.html - make a single document inaccessable;
chmod 666 guestlist.html
- make a single document readable and writable by the world.

For directories:
711 - files in this directory can be read by the outside world;
733 - files can be added to and removed from this directory using a cgi script - but no directory listing;
755
- a listing of this directory can be seen from the outside world (if there is no default "index.html" file);
777 - files can be added to and removed from this directory using a cgi script;
555 - Prevent files from being added and deleted by ftp (could be useful to ensure no files are mistakenly removed from areas that should not be changed).

For files:
644 - file can be read. For most HTML files (744 is also fine, but redundant, for this);
755 - file can be read and executed. For .cgi scripts;
666 - file can be read and changed. For HTML files modified by a script.

General Rules of Thumb

Directories should be set to 755, or 777 if a script is adding and removing files inside the directory - and always have an index page.

Documents should be set to 644, or 666 if they are being changed by a cgi script. Scripts should be set to 755.

If your site is a collaborative venture, user and group permissions should be the same, i.e. 775 and 664, instead of 755 and 644.


Hyperlative Ltd. ©1997