Basic Unix for the newbie

Basic UNIX for the Beginner

  • Introduction
  • The Unix File System
  • Basic Unix Commands
  • Sample Telnet Session
  • The Unix file system In Unix, files are stored in a hierarchically organized file system. This is the same as on Windows and the Macintosh, but might be more confusing because there is no graphical user interface in UNIX to tell you where you are in the hierarchy. The best way to conceptualize the file system (and the way most people refer to it) is as an upside down tree. The directory that contains all other directories is at the apex, and is referred to as the root directory.The directory you are in is the current directory. You specify files and directories by showing how to navigate down the tree to them from either the current directory or the root directory. For example, to show that your directory contains a directory called hello, which contains a file called greet.html, you would type hello/greet.html. The list of containing directories that lead down to a particular directory or file is called the file path.

    The most important thing to remember as you work on a UNIX computer, whether you have used telnet to open a session on it, or are just using an FTP program from your local computer, is that you do not know, as you might on the Macintosh, just by looking at a window name, which directory you are currently in. To find this out, you have to ask the system, (using the pwd command), and have it print the path name that leads to the current directory.

    URLs and other electronic file names indicate the path down the file tree from the root, or from some other point, to a file. So a file path of /usr/smith/work/index.html says that the file index.html is in the directory called work, which is contained in the directory called smith, which is contained in the directory called usr. The initial slash in the path name is used to refer to the root of the directory tree.

    You usually specify file paths with respect to the current directory. In this case, you just list directories below the current one, and shouldn't use an initial slash. In the previous example, if you are in the Smith directory, and want to specify the same index.html file, you would type work/index.html.

    There is a shorthand that allows you to use relative addressing to move up as well as down from the current directory. Two dots indicate the directory that is up one level from the current directory. ../jones/myfile, if you are in the smith directory, would go up one to usr, then down to jones, and then to myfile.

    Every user has a home directory; this is the directory in which you find yourself when you log into your UNIX account, or when you FTP into it.

    Web publishers at pil.net work in two branches of the overall file tree of www.pil.net. The branch that contains users' home directories, and the www branch, which contains files that are viewable through the WWW. When you are in your home directory and you change to your www directory, you are jumping to a place on the WWW branch of the directory tree. The most important thing to know is that, for security reasons, the root of the WWW at pil.net is not the real root of the whole directory tree. This is why the path to a user's home directory might be /home/smith, and the path to the same user's www directory /home/smith/public_html.

    List of basic Unix commands

    Most of the Unix commands that you need for WWW publishing at pil.net can also be done from the FTP program that you use. In Rapid Filer for Windows, Fetch for the Mac or Internet Assistant for Windows 95, use the pulldown menus to: copy files, delete files, rename files, change directories, create directories, and view files within directories. The one thing that you cannot do from an FTP application is to edit files or change your password.

    The following commands are the ones you will need to type on the UNIX command line when you telnet to the WWW server and want to do file manipulation there.

    login - Login command.

    You don't have to type this, it is the command you see when you telnet to the Unix server: www.pil.net

    The www.pil.net server also has a number of aliases. It may also be referred to as: www.pil.net, or www.plantagenet.com

    passwd - Change password

    You will be prompted for your old password, then your new password.

    A legal password must have a minimum of 6 characters. There must be at least 2 alphabetic characters and 1 non alphabetic character. Unix only reads the first 8 characters of a password, although you can make it longer if you want in order to remember it. The Unix server checks the password during weekly system maintenance and if it determines it is too simple or "crackable", an email message will be sent asking you to change your password.

    ls - List the contents of a directory
    ls [-a] [-l] [-F] [-R] [-t]  directory

    directory is the name of the directory whose contents you want to list. If you don't specify it, it will list the current directory.

    -a lists all files, even ones whose name begins with a dot, which are normally invisible.

    -l lists all files in long format, which gives size, date, information on permissions and whether it is a directory or file.

    -F puts a character at the end of each file name which indicates if the file is a directory (/) or program (*).

    -R lists all subdirectories, and their contents, recursively

    -t sorts by time

    You can double up the letters by specifying, for ex. ls -aF in order to see all files, but to also have the character which shows the type of file.

    When you list a directory using the -l option, you get several pieces of information for each file or directory within it. You usually won't need all of this information, but it can come in handy.

    drwxrwxr-x   2 elli     cis          512 Nov  8 15:43 oldstuff
    -rw-rwxr--   1 elli     cis        17949 Nov 14 11:09 foo.sgml

    It is easiest to start reading this file list from right to left. The last piece of information is the name of the file. Right before it is the date and time the file was last modified. The number to the left of that is the size of the file in bytes. (Note that even directories have a size.) Then come the group and owner of the file. The number to the left of the owner is not significant. The leftmost series of letters and dashes show what the file is, and who can read and write to it. If there is a d in the first position, then it is a directory, if there is nothing, then it is a file. An l indicates a symbolic link. The next nine are actually three groups of three symbols. These are the read, write, execute permissions (rwx) for the owner of the file, the group that the owner belongs to, and everyone else. If, for example, the second group of three is rw- that means that the file owner's group can read and edit the file. If the third group reads r-- that means that everyone else can only read the file.

    chmod - Change read, write and execute permissions for a file
    chmod g+w foo.sgml

    This command takes two parameters. The permissions you want to change, and the name of the file whose permissions you want to change. The first parameter is built up as follows: first you put a letter that shows whose permissions are being changed. u stands for the owner, g for the group, and o for everyone else. Then you put a plus or a minus, to show whether you are adding or taking away permissions. Finally, you put the permissions: r for read, w for write and e for execute.

    The example above is the most likely usage of this command. It is making the foo.sgml file writable by the group.

    pwd - Display the current working directory
    pwd
    cd - Change directory
    cd directory

    Changes to the directory indicated by directory. If no directory is specified, then cd changes to the home directory.

    mkdir - Create a directory
    mkdir directory
    rmdir - Delete a directory
    rmdir directory

    Note: you cannot delete a directory unless it is empty, so you either have to remove all the files within a directory first.

    cp - Copy a file
    cp oldfile newfile
    rm - Delete a file
    rm [-i] [-r] filenames

    -i interactive. This prompts you before deleting anything

    -r recursive. Removes a directory and all the files and directories in it. This can be dangerous.

    mv - Rename a file
    mv [-i] oldname newname

    -i interactive. This prompts you before overwriting anything

    logout

    Type this command at the end of a session to end it.

    man - Get help by reading the manual page
    man command_name

    man pages are quite complicated to read. The best way to understand them, or to find what you need is to skim them, looking for relevant information.

    pico - A simple editor
    pico filename

    Pico is the simplest unix text editor to use; you move the cursor around the screen with the arrow keys, and it always shows a list of available commands at the bottom of the screen.

    There are a few simple things to remember about Pico. First of all, all its commands are preceded by the control key. This is indicated by a "hat" or caret character on the screen. The other is that it uses a slightly different vocabulary, so it is important to understand it. "Write Out" means "save". You must write out a file in order to save it while you work. Pico does prompt you to save if you try to quit before you have saved, however. "Uncut Text" means "paste". If you have selected text, you can Cut it, then move the cursor to where ever you want to text to appear, and Uncut it. You can keep Uncutting the same text, as long as you don't Cut new text.

    Selecting text is the most complicated activity in Pico. To select text, you must tell the program where the selection starts, by pressing Control-Shift-6 (Control caret). Then move the cursor using the arrow keys until you have selected the text you want, and one more character to the right. Then you can Cut the text. If you actually want to copy, and not change the original text, you select it, Cut it, then instantly Uncut it. You can then move to where you want the copy, and Uncut it again.

    If you are using NCSA Telnet to connect to www.pil.net, and you are using Pico, you should go to the Setup Keys item in the Session menu, and make all the boxes blank. Otherwise, Telnet will misinterpret some of Pico's keystrokes.

    There is online help for Pico. Press Control-G when you are in the editor.

    Telnet session demonstrating basic Unix commands

    Login command

    login: support
    Password:
    Last login: Mon Sep 18 11:45:31 from henry3.pil.net
    Redhat Linux 4.2

    Change Password command

    www.pil.net% passwd
    passwd:  Changing password for support
    Old password:
    New password:
    Re-enter new  password:

    Directory command: List

    www.pil.net% ls
    Maildir		public_html

    Change Directory command

    www.pil.net% cd public_html
    www.pil.net% ls
    index.html		family.gif	music.wav
    myvacation.html         swim.gif        pool.html
    

    List command: display detailed information

    www.pil.net% ls -l
    total 318
    -rw-r--r--   1 scream   other       2108 Aug 31 15:51 family.gif
    -rw-r--r--   1 scream   other      32593 Sep 14 13:29 music.wav
    
    

    Display the current working directory

    www.pil.net% pwd
    /home/support/public_html

    Go to home directory

    www.pil.net% cd
    www.pil.net% pwd
    /home/support

    Make a new directory

    www.pil.net% ls
    Maildir		public_html
    www.pil.net% mkdir temp
    www.pil.net% ls
    Maildir		public_html	test

    Remove directory

    www.pil.net% rmdir temp
    www.pil.net% ls
    Maildir		public_html

    Copy file command

    www.pil.net% cd public_html
    www.pil.net% ls
    family.gif	index.html	vacation.html
    
    www.pil.net% cp vacation.html vacation.html.old
    www.pil.net% ls
    family.gif	index.html	vacation.html
    vaction.html.old
    

    Delete a file: Remove

    www.pil.net% rm vacation.html.old
    www.pil.net% ls
    family.gif	index.html	vacation.html
    

    Rename a file

    www.pil.net% mv vacation.html vacation.bak
    www.pil.net% ls
    family.gif	index.html	vacation.bak
    vacation.html
    
    

    Logout command

    www.pil.net% logout

    Valid HTML 4.0!!!