web hosting

Technical Reference
Unix Basics


When you've connected to your account with Telnet, you'll work with our UNIX server through something called a command-line interface. If you've ever used MS-DOS, this will probably seem familiar; in fact, some of the commands are identical. If you've never used a command-line interface before, though, don't worry, because it's easy: you just type some instructions (called commands) after a prompt, hit enter, and the computer carries them out. The program that interprets your commands is called a shell, and there are many varieties, but most are quite similar at the simpler levels. The particular shell you'll be using, bash (for Bourne Again SHell), is one of the most popular, and there are a few things you need to know to use it.

The bash$ that appears after you log in is the prompt , and it serves no purpose other than to let you know the computer is ready and waiting to process any instruction you give it. To execute an instruction, you type the necessary command along with any required parameters and optional switches, and hit return. A parameter is a word you type after the command, such as a file name, that is required to perform t he command. For instance, if you give the command telling the system to create a directory, you have to supply a name for the new directory. A switch is a character preceded by a dash that is typed after the command and any parameters and affects the way the instruction will be carried out. For instance, if you wanted to list all the files in a directory in reverse alphabetical order you would type -r after the list command, which is ls, to get ls -r.

The most important command to memorize is the command that accesses the help system. UNIX provides an extensive system of online documentation about all shell commands and many other topics known as manual pages. To get help on any topic with a manual page, simply type man followed by the topic name. For instance, to get help on the list command ls you would type man ls. Man pages are somewhat difficult to read because they are written for users with some UNIX experience, but they are extremely useful in providing a list of all parameters required for a command as well as all available switches.

UNIX is like most operating systems in using files and directories. A file is basically just a named package of data, and a directory is just a "container" for storing other files and directories. A UNIX file or directory name can have as many as 256 characters, which can be just about any letter, number or punctuation mark except a slash (/). At any time, one directory is the current or "working" directory, and the contents of this directory are what are displayed when you type t he list command ls. To see long file listings with sizes, dates, etc., type the ls command with an l switch as in ls -l. To see all files in a directory, including those whose names begin with a period which are usually not displayed, type the ls command with an A switch, as in ls -A. You can type a command with more than one switch at a time, and when you do, you should put all the switches together after one dash. So to see an extended listing of all the files and folders in the current directory, you should type ls -Al. A pathname is the filename appended to its parent directory's name, appended to its parent directory's name, etc. all the way to the top. You can see the contents of a directory contained in the current directory by typing a path instead of just a single directory name. A path is a list of directories separated by slashes, as in public_html/images/picture.jpg, and this is why you can't use slashes in filenames.

A path that starts with a slash, such as /images/picture.gif, means to go up to the root directory to find the directory named images. This is very important to know if you would like to access files in a directory that is not in the working directory, but rather above or parallel to it. For instance, if you have all of the images for your site in an images directory in your public_html directory and you have a CGI script on your server that returns HTML to the browser that contains references to images used elsewhere in the site, you would have to change each image's path to start with a slash, as in img src="/images/background.gif", to get out of the cgi-bin directory so you can access the images directory. Otherwise the browser WILL NOT find your images! For example, if a visitor to your site requested the URL http://www.yourdomain.com/cgi-bin/myscript.pl and it returned HTML that contained an image tag that looked like img src="images/background.gif", the browser would not be able to find background.gif because it would be looking for http://www.yourdomain.com/cgi-bin/images/background.gif, NOT http://www.yourdomain.com/images/background.gif. References in HTML that start with a slash use your public_html directory as their root. You want to make sure to use this technique in any references you make to any images or other files in your notfound.html file, because you never know what directory a visitor's browser will be in when it can't find a file

Here are a few more basic commands that you should know :

  1. To move into a directory contained within the current directory (making it the current directory), type cd directoryname. To move up a directory into the directory that contains the current directory, type cd .. and hit enter. To move into a directory contained within the directory that contains the current directory, combine the two previous commands into cd ../directoryname.
  2. To create a new directory in the current directory, type mkdir newdirectoryname.
  3. To delete an empty directory, type rmdir directoryname. UNIX will not delete a directory that has something in it.
  4. To delete a file, type rm filename. Warning: UNIX will not ask you to confirm the deletion of a file, nor will you ever be able to recover a file once it has been deleted!
  5. To view a text-only file, type more filename. If there is more than a page of text in the file, press the spacebar to scroll down a page, the b key to move back a page, and the q key to quit viewing the file and return to the command prompt.
  6. To copy a file named myfile in the current directory to a directory named mydir that's contained within the current directory, type cp myfile mydir/myfile. Warning: if you copy a file to a directory that already has a file of that name, the original file will be overwritten without asking you, so be careful!
  7. To move a file named myfile from the current directory to a directory named mydir that's contained within the current directory, type mv myfile mydir/myfile. Warning: if you move a file to a directory that already has a file of that name, the original file will be deleted without asking you, so be careful! The mv command is also used to rename files by specifying a path that differs only in the file name. For example, to rename a file named newfile in the current directory to oldfile, you would type mv newfile oldfile.
  8. Like MS-DOS, bash supports wildcards, the * character that stands for any group of characters. So to move all files in the current directory that end in .gif to the images directory, you would type mv *.gif images and hit enter. To move ALL the files in the current directory to the images directory, you would type mv * images.

Table of Contents
Visit Our Virtual Mall

©November, 1997
MJ Enterprises
1221 Kara Lane
Modesto, Ca. 95355
Email Us

web hosting web hostin policies Web Hosting Support Manual Web Hosting Specs Web Hosting Packages Contact Web Hosting