A SIMPLE UNIX PRIMER
I. Introduction
Whether you are the person who maintains some web pages on a UNIX-based computer system or simply wanted to frustrate yourself by learning another computer operating system, this tutorial is for you. UNIX may seem a bit strange to "speak" at first, but its rudiments are easily learned.
This short tutorial will attempt to shed some light on UNIX, so that it will not remain quit so weird. For more information, check out a beginning book such as UNIX For Dummies by John R. Levine and Margaret Levine Young.II. Dealing With Files
Here are a few commands that enable a user on a UNIX system to navigate the file structure on such a computer. All of these commands are typed in lowercase and should be followed by <enter>.
|
ls |
"list" the names of the files in the current directory |
|
ls -l |more |
"list-long" showing the permissions, name, and date of creation/modification for each file in the current directory; the "|more" option is optional (it allows the directory to be listed one screen-full at a time) |
|
rm filename |
"remove" the named file from the directory |
|
cp file1 file2 |
"copy" file1 to file2 (these files may be in different directories, if so, specify the full path in their names) |
|
mv file1 file2 |
"move" file1 to file2 (copies file1 to file2 and then deletes file1; may be used to rename a file) |
|
mkdir dirname |
"make a new directory" with the name dirname |
|
cd dirname |
"change current directory" to the directory named |
|
cat filename |
"catalog" a file (types out the contents of a file on the screen) |
Notes:
There is actually a upper limit of several hundred characters for file names, but for all practical purposes it is unlimited. Windows 95 users who are used to placing spaces in a file name should refrain from this habit on a UNIX machine. Instead use the underscore character "_" or a hyphen, or simply use upper and lowercase characters appropriately. UNIX views upper and lower case characters as being different characters. Thus "Seminar," "seminar" and "SemiNar" are all valid but different filenames.
For example, the command
|
rm /Users/rbowman/temp-text |
will delete the file "temp-text" in the subdirectory "rbowman" of the subdirectory "Users" which is in the top-most directory. Former MS-DOS users should note that the delimiting character is "/" not the reverse slash "\" used in DOS filenames.
Extreme care must be used when using wild cards with some commands such as the "remove" command rm. The "*" can be used to represent any number of any type of character while "?" can stand in place of any single character. For example,
|
rm *tt?? |
would delete the files little and alittle but would not touch the file littl.
Most terminal programs, such as the telnet program or HyperTerminal under Windows, have a menu option that will capture a text file as it is typed out on the remote UNIX computer. To transfer a text file to your computer from the UNIX machine, select the text file transfer or logging option from your terminal program, then type in the appropriate cat command and press <Enter>. To terminate the text capture mode, return to the terminal programs menu and stop the capture. The text file on your computer may need to have the first and last lines removed to return it to its original content.
III. Changing The Permissions On Files
Occasionally, for reasons known only to the imps inside of a UNIX computer, the permissions on a file will not be set appropriately for the world to read a web page. Or maybe you would like to let someone else in your "group" have permission to edit a web page that you have written. In either case, the file permissions must be set correctly.
As far as a UNIX computer is concerned, the file universe is divided into the owner, the work group, and the world. The permissions for each of these is set through three binary "switches." Below is a sample UNIX directory listing using the "ls -l" command showing the permissions for a file and a directory.
-rw-rw-r-- 1 rbowman faculty 8979 May 17 12:29 bowman.html
drwxr-xr-x 2 rbowman faculty 512 Sep 12 18:36 courses
The file or directory name is at the end of a given line in the listing. In this case, "rbowman" is the owner of the file and directory, and the work group is "faculty." At the very beginning of each line is a ten-character code. The first character tells whether the listing is for a directory (d), a link (l) or a file (-). Following this letter are three sets of three characters each. The first set shows the permissions for the owner, the second set is for the group, and the second set is for the world.
In each set the three characters are in the order of read (r), write (w) and execute (x). If a character is present that user has the appropriate permission. For example for the file "bowman.html", the world has the permissions of "r--". This means that the world can read but not write or execute that file.
For web pages, a file should have the permissions of "rw-rw-r--" which corresponds to the number 664. For a directory everyone must also be able to execute it, so that the permissions for a directory must be "rwxrwxr-x" which corresponds to 775.
To set the permissions for a file, use the command:
|
chmod 664 filename |
To change the permissions on all files in a directory but not those of any subdirectories, simply replace the filename with the wildcard, "*".
Similarly, for a directory, the command is:
|
chmod 775 dirname |
IV. Let Me Out Of Here!!
Before beginning working on a new system, it is a good idea to know how to get out of the system, i.e., logoff of the computer. In most implementations of UNIX, the necessary command to end a session is simply exit (lowercase) followed by <enter>. In some rare situations, lo or logoff may be the requisite command. If all else fails and you are connected through a terminal program, simply use the file menu and disconnect from the remote system.
--
Richard L. Bowman (18-Sep-97)