Beginning UNIX and Telnet Tutorial






This tutorial is meant mostly for people who are taking the Web design tutorial and want to be able to manage their own web site on a UNIX host from a home computer. It covers the commands that most beginner users will need to setup and manipulate their files.
It is not meant to be a complete course on the internals of the UNIX o/s.
If you are a beginner and this tutorial can be of some use to you, go ahead and enjoy!


What is UNIX?

UNIX is an operating system just like DOS and Macintosh OS are operating systems. The big advantage that UNIX offers is that it is more efficient at handling multiple users. It is therefore the operating system of choice when running servers. When you create a web site and host it on a web server with hundreds or even thousands of other web sites, the odds are that the host is using UNIX as an operating system. Unfortunately, UNIX is not quite as user friendly as Windows so you have to spend a little time learning commands in text mode.

First you're going to need to log into your host. To do this you will need a telnet program. The telnet program is a terminal emulation client . That simply means that your remote computer is connected to the host as if it were a console and you can issue commands to the operating system.

A very good, yet simple telnet program to get is called SimpTerm. It's distributed as freeware (please read the copywrite notice) and you can get it from here: SimpTerm.

Things you are going to need to know:

1.The account name or userid.

2.The password you chose when you opened your account.



Logging on and off from Windows


1. Create a shortcut to SimpTerm on your desktop.

2. Open SimpTerm.

3. Hit Alt-D or the "Create new connection" icon.

4. Enter your URL, for example: www.yourname.com to connect

5. Enter your username and password to connect to your account on the host.





6. When you're finished, type exit to end your session.

7. Close the telnet window and you're done.


UNIX Files


WARNING!

I've mentionned this one several times in other places but I'll repeat in case you missed it.

If you are used to working in Windows, you know that file names, folder names, etc. are not case-sensitive. UPPERCASE or lowercase doesn't really matter.

But most Internet servers work in UNIX, not Windows. And in UNIX all those file names are case-sensitive. My "Pictures" directory will not be found if I write it as "pictures". This does not apply to the actual HTML code - just to the file structure on the server.

So, a word of advice: write everything (files, folders, paths) in lowercase. For example, when I need to get a picture, I will write the code as: "../images/pic1.gif" and so on.




Since most of what we do on computers involves working with a computer file we'll spend a minute talking about how UNIX organizes files. Like Windows, the file system is organized in a hierarchical fashion like the branches on a tree. These branches are called directories. Each user has a personal home directory. When you log in to your account you will automatically be in your home directory. You can find out what directory you are in by typing the command pwd. For example type pwd in your shell tool window and you will see something like:

/home/mikel/

You can use this command to determine what directory you are in. But your prompt 'opt2/home3/profsr>' will also identify the directory you are working in.

The rest of this tutorial is designed to teach you the basic UNIX commands you will need to know in order to manipulate the files in your account.


UNIX Commands


Listing the files in a directory: ls

If you type ls you will see a list of files in your directory. So, type ls in your shell window and hit return. Chances are you will not see anything since your directory is empty. However, there are some files hidden in your directory that do not appear since they most likely not need to be changed (they are for 'administrative' purposes).

Here are a few recommended options you should try with ls:

ls -a

- shows you all the files in your directory, including hidden ones.

ls -l

- shows you the files in your directory in long format. Giving you the ability to see file permissions, owner of file, creation date, and filename.

ls -al

- combination of the two above.

It is recommended you try and use ls -l at most times to easily fammiliarize yourself with the files you are working with.


Creating a text file: cat

You will need to type the following commands in order to create your dummy text file.
Enter a return after each line. To end, hold down your control key and press c, in other words, do <ctrl><c>.
Note the use of the > sign after the command; cat without the > is used to display the content of the file, as we'll see in a minute.

cat > test.txt
this is a test file
it contains dummy lines

<ctrl><c>

Once you've created your file you can check that it now exists:

ls -l


Copying a file: cp

To create a copy of an existing file with a new name:

cp test.txt test.txt.backup

Once you are finished you will have created a file called test.txt.backup it will be an identical copy of the original file.

Do: ls -l to check that it does in fact exist.





Looking at a file: more or cat

There are two UNIX commands that allow you to look at a file:

more and cat

If you want an entire file to dump to your screen at once type:

cat test.txt

You can now see what was in the file that you created. Now type:

cat test.txt.backup

You can see that you successfully copied the file test.txt to the file test.txt.backup.

The second way to look at a file, more, is better if a file is longer than the window you are going to look at it in. The more command allows you to scroll down through a document one screen full at a time. You probably do not have a file bigger than one page in your directory so for the time being type:

more test.txt


Removing (deleting) a file: rm

This command is used to permanently delete a file. To delete the file you created in the previous example, type:

rm test.txt.backup

To simplify navigation through the file system, it is recommended that you delete files that are unnecessary. You also do it to conserve storage since most accounts have limits on the amount of storage space you are allocated.


Creating a new directory: mkdir

To create a new directory called temp, under the directory you are now in, type:

mkdir temp


Changing directories: cd

To go into temp, the directory you just created, type:

cd temp


To move back one directory, to your home directory in this case, type:

cd ..

Suppose you've created several directories within directories and you want to quickly go back to you home directory without having to type cd .. several times. If you type:

cd

you will automatically move back to your home directory from where ever you are.


Copying and Moving files from one directory to another: cp and mv

You should now be in your home directory. Type pwd to make sure.
To copy a file from the current directory to a subdirectory, use the cp command:

cp test.txt temp/test2.txt

This will have created a copy of test.txt in directory temp and will have named it test2.txt

The mv command has a couple uses. You can move a file from one directory to another (without leaving a copy of the original file in the first directory, like the cp command does) or you can change the name of the file. To use this command to rename your file test.txt to a new name, test.html, type:

mv test.txt test.html

Now type ls -l to make sure the file test.txt has been replaced with the file test.html. Also, type 'more test.html' to verify that test.html is the same as test.txt was. To move the file test.html to your new directory temp type:

mv test.html temp

Go to your directory temp and type ls -l to make sure that test.html is in there.


Removing a directory - rmdir

Once you're done working with a directory you can remove it from the file structure. For example:

rmdir temp will work but, only if temp is empty - it does not contain files.

To remove a directory and the files it contains:

rm -r temp


Editing a file: pico

The basic file editor provided with UNIX is called pico. It is simple to use and allows you to edit your text files with the greatest of ease.
To edit the file test.html type:

pico text.html

Now that you have the file test.html in your text editor, make some changes to the file -- add another line to it:





Once you are done typing that line you will need to hold down the control key and press O (Control-O to save) and then hold down the control key and press X (Control-X to quit). You should now be out of pico and back at the UNIX prompt.

Type:

more test.html

at your shell prompt to verify that your changes were correctly saved.