Just a little Unix (and computer history)
for COMS 326 Web Production students
by Bob Stepno
Most Web pages these days are created with Content Management Systems or dedicated Web page editors like Adobe's Dreamweaver or Apple's iWeb. However, you also can edit your http://www.radford.edu/~yourname Web (HTML) pages with the simplest of text editors, even edit them directly on the Web server, which is a Unix computer somewhere across campus. At Radford, you get there by connecting to your "H drive" or "Home" space using a "terminal" program. This page of mine tells you how.
On the Macintosh, the program is named "Terminal." If someone hasn't put a shortcut to it in the Dock, you should find it in the Applications folder, in its Utilities subfolder.
(By the way, Macintosh and Windows users generally use the word "folder"; Unix uses the word "directory" for the same space.)
Optional history lesson (Unix part 1A)
Both the Unix operating system and the word "terminal" date back to the days before small personal computers, when users sat at devices called terminals connected to one multi-user mainframe computer. A program like "Terminal" on the Macintosh "emulates" one of those old terminals.(See terminal emulator.) The earliest terminals had no "CPU" chip of its own, just a keyboard and display; the display could be either a printer or a screen. It might display only upper-case characters in a single type font, with no "what you see is what you get" touches, like bold or underlined text. Those terminals also had much simpler keyboards than today's Macs and PCs. (That's why some of those keys may not do anything when you are inside a terminal-emulator program.)Those basic terminals were designed to enter commands one line at a time, which is why an important key is marked "Enter" on some keyboards and "Return" on others. "Return" was the typewriter word for "return to the start of a line," and the first terminals really were little more than teletype-style typewriters. You typed something; the computer typed back something. When more sophisticated terminals became available, the old ones were sometimes called "dumb terminals."
The early video display terminals, which were a little smarter, had model names like "VT52" and "VT100." They still had no mice, so the keyboard was the only way to give instructions to the computer, either by typing on a "command line," or by running programs that recognized special key combinations to control the program.
That's the origin of the key labeled "control" that we still have on Macs and PCs today, and you can still use it to perform special functions within Unix programs.
Terminal opens a plain-text window on your screen in black and white, but its Preferences settings can change the size and color of the window and its display font. You can have more than one terminal window open. You can cut and paste plain text between other Macintosh applications and the terminal. And you can make the terminal window larger or smaller by holding the "command" key and pressing "+" or "-" (plus or minus).
Underneath its fancy desktop, each of our lab Macintoshes is actually a Unix computer with the OS-X user interface running "on top" of Unix. "Terminal" takes you to the Unix level of the Macintosh, and you can use the terminal to connect to other Unix computers on the Internet. The Web server that we all see as http://www.radford.edu and the personal storage space we all see as an "H drive" is a server called "ruacad" when we connect with a terminal. Your H-drive is a folder with your e-mail name. Your public Web space is a folder inside that one, named "public_html."
With the terminal program, you can connect to Radford's Web server using the Unix operating system's Secure SHell program, ssh for short. (Unix systems like to have commands in all lower-case letters.) Since this class meets in a Mac lab, this page only has instructions for that system. On Windows computers, you may use an "ssh client" or "sftp" program rather than a simple terminal. Among them are PuTTY and TTSSH, which are both free. Google can find them for you.
Unix commands: Unix intro page 2
Using the Macintosh (Unix) terminal program, the command to connect to the server is:
ssh yourusername@ruacad.radford.edu
"yourusername" is the same as your e-mail name, minus the "@radford.edu"
The ssh program will display the server's request for your password, the same one you use for e-mail or the RU portal.
When it accepts your password, you are logged into the Web server, and you can use Unix commands or run Unix programs on that "remote" machine.
The first thing you will see on the server is a "shell menu" that looks like this:
TERM=vt100 Version 3.0 DATE: 08/24/09
Radford University Master Menu
-------------------------------------------------------------------
1) Mail Menu
2) News Menu
3) Inactive Selection
4) Inactive Selection
5) Inactive Selection
6) Library / Reference Menu
7) Inactive Selection
8) Talk IRC
9) Exit to C-Shell (command prompt)
10) General UNIX commands & Utilities
11) Reserve classroom multimedia cart
12) View MOTD
13) Lynx (INTERNET - WWW Browser)
14) Logout
(q) Quit - Logoff
(h) help
Your Choice:
Choose Option 9 (Exit to C Shell) and you will be at the Unix command line, with your Macintosh or PC set to emulate a vt100 terminal.
We will work in a common unix editor called "pico." If you are familar with another unix editor, such as emacs, xemacs or vi, feel free to use them, but you are on your own about their editing commands. One benefit of pico is its simplicity -- all of the main editing commands are visible at all times.
You should not run into this problem, but... IF the server types back that you are using a terminal that cannot run pico, type this command:setenv TERM vt100That will reset the server to expect the more common "vt100" style terminal settings.
Notice that when you have logged in, the terminal "command line prompt" changes from the name of your Macintosh to the name of the server, followed by the "directory path" to your current position on the computer.
ruacad @ /home/rstepno/ >
You can use the "cd" (change directory) command to get into your
public_html directory and the "ls" (list) command to list the
documents in
that directory. First, type "cd public_html" (without the quote
marks)
This is what the command-line
prompt looks like when I am in the public_html directory, which is my "www.radford.edu/~rstepno" Web space, then
type the "ls" (list files) command.
ruacad @ /home/rstepno/public_html >
ruacad @ /home/rstepno/public_html > ls
(Notice that Unix uses the slash mark / to indicate directories contained within directories -- "folders within folders" to Mac and Windows users.)
Common commands:
- To see a longer version of the list of documents and directories,
add a
space, a hyphen and an l (for long):
ls -l
- To change to a new directory (folder) within the current directory:
cd nameofdirectory
- To change back to the directory "above" the current directory:
cd ..
(The two dots mean "up one directory level." Remembering that the slash mark can separate directories, can you guess what "cd ../.." would do?)
- To run a simple text editor:
pico
- To edit a new or existing html document with
pico:
pico documentname.html
- To quit pico: Control-x (see the menu at the bottom of the screen, where ^ mark means "Hold down the control key while you press a letter key.")
- To logout of ruacad and close the ssh connection, just type "exit"
- To close the terminal: Type exit again, then choose "quit terminal" from the Macintosh Terminal menu.
Shortcuts: The Unix command line has two useful shortcut keys built in -- the tab key and the up-arrow key.
The up-arrow key will step backward through commands you have typed recently. The tab key will auto-complete all or part of a command. That is, if you type "pico m" (on the way to "pico myfile.txt") and press the tab key, the system will finish typing for you, if that is your only file beginning with "m." If you have both "myfile.txt" and "myfile.html," the tab key will get you only the "myfile." part of the name -- you will have to finish adding the "txt" or "html"
Editors: Most Unix computers, including the ruacad computer, have other editors, but pico is probably the simplest, because its basic control key commands are always visible on screen. Other popular Unix editors include nano (based on pico), vi or vim, and emacs or xemacs.
Going public (Unix intro page 3)
Web pages or other documents you want to make visible to the public must be placed in the directory named "public_html"
However, even documents created in the public_html directory begin as "readable only by owner." To finish the job of making your work public, Radford offers a utility on the myRU portal page, as described on my other instruction sheet.
You also can set access permissions without returning to the portal, by using the powerful Unix "change mode" command called "chmod" for short.
The command has three parts: The command name, a code for the change you want made, and the name of the document whose "read" or "write" permissions you want to change. For purposes of this course, the simplest approach is to remember that "a+r" ("all read") is a code you can use to make any document readable by the global public. It will be writable only by you, the owner. You give the command in this form, where "filename.html" is the name of your document:
chmod a+r filename.html
That command should not be used on whole directories or combined groups of documents, programs and directories, because it will remove the "execute" permission. (Documents are not "executable.")
To add global read permission to directories and all the files they contain, use this command:
chmod -R a+rX directorynamehere
The first R and the final X must be capital letters. The "-R" means "recursive" (repeat the setting for all files). The capital X means to add the execute permission only to directories. An alternative is to use a numerical version of the chmod command, but be sure to type the numbers correctly:
chmod 755 filenamehere That will add the "read" and "execute" permissions to any file, directory or program named. (Execute permission is not needed for documents, but setting it does no harm.)The long file list command (ls -l) shows the chmod settings for all the files in the current directory. The letters d, r, w and x indicate whether the item is a directory (d) and whether the directory or file can be read (r), written (w), or executed as a program (x). "Written" really means "write, create or delete."
The first character in the line indicates directory (d) or file (-). The next three characters indicate the permissions granted to you, the owner of the file or directory. The three after that indicate permissions for members of a group (probably set to everyone who has an account on the server); the last three are permissions for everyone on the Internet. Of course you should never see a "w" in that last group of three, because you don't want to let other people write or delete your documents.
Simple example, here's how I made a new document "test.html" readable:
ruacad @ /home/rstepno/public_html > ruacad @ /home/rstepno/public_html > ls -l drwxr-xr-x 5 rstepno faculty 0 2009-03-24 15:00 09spring/ -rw-r--r-- 1 rstepno faculty 13140 2009-03-05 13:58 index.html -rw------- 1 rstepno faculty 15 2009-05-31 20:40 test.html [That shows the directory before I gave the "chmod" command below.] ruacad @ /home/rstepno/public_html > chmod a+r test.html [This will show the directory after the command. Notice the difference.] ruacad @ /home/rstepno/public_html > ls -l drwxr-xr-x 5 rstepno faculty 0 2009-03-24 15:00 09spring/ -rw-r--r-- 1 rstepno faculty 13140 2009-03-05 13:58 index.html -rw----r-- 1 rstepno faculty 15 2009-05-31 20:50 test.html[The r-- means that "all others" can read the document. ]
Want to learn more?
For a more thorough explanation of chmod, including the "Symbolic method" of setting access with those "a+r" codes, see this detailed description at the University of Indiana. There are plenty of Unix books available, and plenty of free tutorials and reference pages online. (Here's one.) If you are already fairly technical, each Unix command has a "user's manual page," known as a "man page" available within the terminal, but written for experienced unix users. If you care to take a look, just type "man" followed by the name of the command you are interested in; for example, you can see all the variations of the "ls" command by typing "man ls" -- and there are plenty of them.
Don't like scrolling? See the Multi-page version