Lab 0: Unix, vi and Web Pages

Lab 0: Unix, vi and Web Pages By the end of this lab, you will be able to: • Know the basics of the vi text editor • Create a simple web page There ar...
1 downloads 0 Views 213KB Size
Lab 0: Unix, vi and Web Pages By the end of this lab, you will be able to: • Know the basics of the vi text editor • Create a simple web page There are 5 parts to this lab: Part 1: Introduction Part 2: Operating Systems Part 3: Using vi Part 4: Starting Your Web Page Part 5: Submitting Your Work In this lab, we will highlight instructions for what you have to submit in a yellow box like this one. Note: Some of this Lab will be review since we have covered it in our homework.

Part 1: Introduction Welcome to the first lab for CS 201. In the next few hours, you'll learn how to use the vi text editor. You'll also get started on your own web page. At the end, you'll be asked to submit answers to some questions that will be asked along the way. You can do this lab anywhere you like with your own computer, so long as you are running some flavor of Linux, Windows or Mac OS X. You are welcome to bring your own laptop to my office to get help. In particular, if you are running a different version of Windows or Mac OS and the instructions don't seem to fit, please let me know as soon as possible. I realize that for many of you, much of this lab will seem incredibly familiar and trivial, but for others, some or even all of it will be new. If you don't know much about using an operating system, follow the steps in order and ask me for assistance at any time. Since software and hardware change every year, often in subtle ways, inevitably something won't work exactly as described here. In particular, Windows 8 and 10 machines always confound me. It is hard to catch all the little differences and to spell out the steps as clearly as we would like. If you find something wrong with the instructions, again, contact me as soon as you can. If not, do what you can and don't worry about it. In any case, please let me know. Thanks.

Part 2: Operating Systems Windows, Mac OS X, and Linux/Unix are all operating systems, which are programs that manage the resources of a computer for you. An operating system lets you run programs like browsers and word processors and iTunes; it lets you access information on disks; it lets you use attached devices like printers and scanners; and it lets you communicate with other machines via a network. "Windows" is a family of operating systems from Microsoft. Microsoft cranks out a new version every few years: Windows XP has been around since 2001, Vista arrived in 2006, Windows 7 in 2010, Windows 8 in 2012, and Windows 10 in 2014. OS X 10.11 "El Capitan," the latest version of Mac OS, arrived in 2015. Unix and Linux are also operating systems, not from Microsoft or Apple, that run on a wide variety of hardware, including phones, tablets and e-book readers. All operating systems perform the same basic functions, though with myriad differences in style, philosophy, and details. One of the main functions of an operating system is to provide an environment in which you can run programs. Operating systems allow you to run several programs at once, switching your attention from one to another at will. Some, like Unix, are mostly controlled by typing on the keyboard. Others are graphical and are mostly controlled with a mouse. Mac OS X has a glossy mouse interface but there's a Unix implementation in the background. Text Files Word processing is one of the most frequent computer tasks, and most people have used Microsoft Word to process documents. But there are plenty of times when you don't want a formatted document nor the proprietary Word format. Every system has a variety of editors that let you create plain ASCII text with no additional formatting or other goo. On Windows, there is Notepad, or you can use Wordpad if you save your files as ".txt" format. You can find these programs from the Start menu in places like All Programs | Accessories or All Programs | Basic Applications. I strongly advise against using Word for text files. On a Mac, there is TextEdit (in Go | Applications). Unfortunately TextEdit is sometimes too smart for its own good. Use Preferences | New Document to set "Plain Text". Do not use "rich text format" (.rtf). Under Open and Save, uncheck the box that says "Add '.txt' extension to plain text files". On Unix systems, traditionally there have been two text editors, vi and emacs. We will be using vi for this lab. For the rest of this lab, you will record your work in a plain ASCII text file using vi, as you go along, then submit it at the end.

Part 3: Using vi Your supplemental textbook, The Linux Command Line, covers vi in Chapter 12 and there is a interactive tutorial in your account named vi_tutor. You should leave this document now and read Chapter 12 and practice using vi in your account. $ vi vi_tutor You really do not need all the features introduced in these two references for this lab but the more you learn, the more comfortable you will become with this new kind of text editor. Getting Started In your home directory, open the lab0.txt using vi, then begin collecting data for submission: • Type a line with your name and account number (e.g., cs201101). • Type a second line naming the operating system and version that you typically use for your computing (e.g., Linux, Windows 7 or Mac OS X 10.6 or whatever). • Save the document as a file named lab0.txt.

Leave your editor running. You will be adding content to this file for the rest of the lab. Each time you add something, save the file; this (usually) protects you in case something goes awry, and is always a good idea.

Part 4: Using Unix Unix is an operating system; like Windows and Mac OS X; it controls the resources of a computer on your behalf. Unix has been around a lot longer than other systems, and runs on many more different kinds of computers. Many of the Internet and Web services that you use run on Unix machines, and most of the central computing services at SFASU are based on Unix. The web pages that you will create in the next few labs are also stored in files on Unix systems, so it will help you to understand at least the rudiments of how to access and use the department's Unix systems. The Linux operating system is a variant of Unix, so anything you learn about Unix will apply to Linux as well; indeed, you will use CS's Linux systems for this lab. We will lump Linux and variants under the generic term "Unix", since for our purposes they are all the same. Mac OS X is also a Unix variant. Although the Mac has an even glitzier graphical interface than Windows, underneath is the full power of Unix, a nice combination. If you're using a Mac, start Terminal (in Applications / Utilities) and all of the Unix commands described here will run the same.

Unix systems are more reliable and secure than Windows (or so it is believed by Unix aficionados) and present programmers with more convenient access to the internals of the machine. As a result, although Windows is dominant in offices and homes, Unix is often used to support infrastructure functions (the back office); familiar sites like Google, Amazon and Yahoo all use Unix or Linux. Using the Webserver Search at netcraft.com (middle right, "What's that site running?"), find another major web site that uses Unix or Linux. (You might have to do some digging to determine whether a name like yahoo.com is Unix-based or not.) Add a line to lab0.txt with the site name and the name of the specific Unix variant. Find a major web site (other than microsoft.com or msnbc.com) that doesn't use Unix or Linux. Add a line to lab0.txt with the site name and the operating system name. (Hint: checking several other well-known sites is a reasonable approach.)

Why use Unix? It largely depends on what task you are trying to accomplish. For example, Windows has an enormous collection of useful programs, many of which have no Unix equivalent, and Windows comes installed on most PC's. Unix is a good environment for writing programs, however, especially programs that are meant to work on more than one kind of computer, so it is often preferred by programmers. It supports a bunch of users on one machine, which Windows does not. Meanwhile, don't worry if Unix seems strange at first. You will need to use it very often in future courses, so it is helpful to know how to move around in it. And if you own a Mac, knowing Unix will give you a new way to use your computer and let you do operations that aren't possible with the point and click interface. Add a line to lab0.txt show me you are logged in with the whoami command. Run the command ls -l on your home Unix directory, and copy the first two lines of the result into lab0.txt by Copy and Paste. (Don't include the line that says "total ..."; it's boring. Copy the next two lines.) Type the command who | wc. (That character is the vertical bar, not the letter i or ell; it is often above the Enter key and may look like two short dashed lines.) This will tell you how many users are logged into the Unix system (in the first of the three numbers it prints). Add a line to lab0.txt giving the number of users logged in. At this point, you should have 8 lines in lab0.txt.

Part 5: Starting your Web Page A web page is a text document similar to the one you've been creating for this lab, but there are two important differences between lab0.txt and a web page. First, a web page is stored in a specific folder where it is visible on the web. Second, whereas lab0.txt is written so that it's easy for a person to read, a web page is written so that a browser can format it the way you want. With the second condition in mind, let's start making a web page. Open a new document in the vi editor and save it as lab0.html. Web pages are written using a special language called HTML, which stands for HyperText Markup Language. Mostly HTML is ordinary text, but it includes formatting information that describes the layout. This extra information is contained in a set of tags, which are ordinary text surrounded by < and > signs. They give the browser information about how to display the text. The skeleton of any web page looks like this: Title of the Web Page Goes Here Content of the web page goes here

In Lab 1 we will go into detail about what exactly this means, but for the time being it's safe to simply copy this text and paste it into your new document. Remember to save the document every time you make a change. Save this document lab0.html, and copy it to the public_html directory in your account. Start your web browser of choice on your computer. You can preview your page by opening the document which you just saved in the browser, by giving the browser the address: http://cs.sfasu.edu/cs2011xx/lab0.html Remember to substitute your account number for the xx in the address above. Right now it isn't very interesting, since it just says "Content of the web page goes here", so next you're going to fix that, by adding content and a title. Replace "Title of the Web Page Goes Here" by a brief title. Replace "Content of the web page goes here" by your name. Test these modifications by loading the page in your browser as described above. You will

have to save the file in vi in your account and then reload in the local browser before you will see the change; don't forget this! Unlike the Title tags, we put the Body tags on their own lines rather than sharing a line with the content. This illustrates an important point of HTML syntax. The browser doesn't care where you break lines of text while you're writing your page -- it just ignores line breaks. Thus web page designers have to use a special tag to designate where to break lines when the page is displayed. This tag is the
tag. Add a
tag after your name, then add four more lines with the following information: • The number of lines in your lab0.txt file. • The name of the operating system your browser is on (e.g., Windows Vista, Windows 7, Mac OS X, etc.). • Where you did the lab: "dorm room" or "Friend's house" or whatever. • What browser you used to view the page (e.g., Firefox, Safari, Internet Explorer, etc.). • Use a
tag after each line so they appear as separate lines. Test this modification by saving the file in vi and loading the page in your browser. Each piece of information should appear on its own line, so be careful where you put your
tags.

Part 6: Submitting your work At the end of most labs, you will be asked to leave your results in your account and use the submit command. Be sure to include everything I asked for. If you have comments or suggestions, I'd be happy to get those as well. Check your work Make sure you've done all the steps. Make sure your web page is accessible at http://cs.sfasu.edu/your_account/lab0.html. Ask a friend to look at it from his or her browser. If they can see it, so can we; if they can't, we can't. Since you made alterations to the lab0.html file in the public_html directory, copy it to your home directory, overwriting the original version you started with. Submit your work Leave your work in your cs201 account. I will grade it from there. Make sure you do not make any alterations past the due date and time given at the top of this lab. Also $ submit cs2011 lab0.txt lab0.html Note: you must be in the same directory as the file to successfully use the submit command.