Welcome PradhiKarthik: UNIX

Sunday, September 19, 2010

UNIX

I. Introduction: What is Unix?
II. Commands and Jobs
III. Files and Paths
IV. Basic Commands
      a. Shell Commands
      b. File Management
      c. File Manipulation
      d. Wildcard Resolution
      e. Input/Output Redirection
V. Editors
VI. Mail
VII. Networking


I. Introduction: What is Unix?
                          Unix is an operating system. An operating system tells a computer how to process commands and programs that the users give it. An operating system is the foundation software of a machine; it schedules tasks, allocates storage, and presents a default interface to the user between applications. Some other operating systems are DOS, Windows, BeOS, Linux, and the Macintosh OS.
                           Unix is a highly developed, mature, very stable, complex, and immensely powerful operating system. Unix provides multi-tasking, multi-user abilities that allow multiple programs to run on one computer simultaneously, and multiple users to use one computer simultaneously; while most operating systems only work on a specific type of machine, Unix has different flavors so that it can be run on many different types of machines. In addition to the operating system, there is a shell; the shell takes commands from the user and modifies them to suit the operating system.
Since there are several different shells, this allows you to use Unix for different purposes, since each behaves in different ways. This is a powerful aspect of Unix which is not shared by Windows or the Macintosh Operating Systems.
                           If you have used the DOS command line, some of what follows will be familiar. If you have mostly worked with graphical user interface systems such as Windows or Mac OS, it may take a while before you become comfortable working with Unix.

II. Commands and Jobs
Some introductory notes about Unix commands and this guide:
File commands are designated by bold type; parameters are designated by italic type; optional parameters are shown enclosed in brackets []. Unix makes use of extra keys called control characters. These are entered by holding down on the control key and then pressing the key you want. These are denoted with a ^ in front of the character (so Control-c is written as <^c>).

Note: Some of these commands may conflict with keys used by the software on your terminal computer. For instance, if you type <^s> while using NCSA Telnet on the Macintosh, the screen will freeze until you type <^q>. To prevent this, go to the Session menu, select Setup keys... and delete the suggested keys.


• Unix is case-sensitive. Always use lower case unless otherwise specified.
• Unix commands take two forms of parameters: plain parameters, like file names; and flags, which are preceded by a hyphen (-). Multiple flags can be appended to each other and require only one hyphen. Most commands accept file name wildcards. The wildcards are * and ?. For example:
ls -la *txt
               l and a are flags; * is a wildcard for any files ending with txt.

• To get online help with any command, use the man command (for manual).
man [command]
              This will scroll the instructions on how to use the command, pausing after each page until you type .
man -k pattern
              This will search through the manual pages for any containing the pattern specified. For example, any command involving formatting could be found with man -k format.
• To abort an ongoing process in Unix, <^c> is used, while <^z> is used to suspend a process so that it can be restarted later. Suspended Jobs Whenever you start a program or give a command on Unix, you start a job or process that has an associated number and Process ID. If you quit cleanly from this, either by choosing to exit/quit or by typing <^c>, the computer kills the process and finishes the job. However, if you do not exit cleanly, usually by pressing <^z>, the computer keeps the job running. Jobs can be looked at with their associated process IDs by using jobs -l (el, not a one). The job can then be killed using kill -9 pid#.
                  If you try to log out when you have suspended jobs, the machine will tell you that they are there. In order to log out, type logout or exit again. This may give you problems, since some processes (particularly Elm) leave files that wil have to be removed for them to work again. You can restart jobs by typing fg(for foreground); this will bring them to the screen and will allow you to quit from it properly. You can also restart them in the background by typing bg. This allows them to run without tying up your screen. When they begin in the background, the job number with the Process ID is printed on your screen. When they are finished, the job number comes up with the word “Done”.

III. Files and Paths

The C-shell
                   Unix uses shells that take commands from the user and supply them to the operating system. Unix has many different shells, such as sh, sh5, csh, Bourne, zsh, and ksh. All of these have somewhat different characteristics. The shell which we use almost exclusively at Haverford is the C shell, or csh. This is the shell which provides you with the login prompt, lets you change directories, write interactive scripts, and much more. Only csh is covered in this overview. Look in the manual pages for information on the other shells.

Special Files

Unix, like most other operating systems, employs a hierarchy of files and directories. Unix knows only one structuring element for this hierarchy: files.Directories are as much files as data or executable files are. The data of directory entries are links to superordinate and subordinate directories in the hierarchy. Directories fit inside directories, forming directory trees. In order to describe a file completely, it is necessary to point out where in the directory tree the file resides. This is done by giving the path of the file, a long string of directories and subdirectories above the file. For example:
/home/venus/jbloggs/doc.txt
Is the file doc.txt that resides within the directory jbloggs, which in turn resides within the directory venus, and so on. The directory “/” is referred to as the root directory. Both directories and files can be “hidden”, i.e., they do not show up when other files are listed. This is achieved by having a “.” as the first character of the filename.
The system has a record which stores the user’s username, password, real name, and home directory.
When a user logs on, the current working directory (cwd) is set to the registered home directory. For most users on Unix, their home directory will be /home/venus/. All files which contain the abbreviation “rc” are startup files.
.login
This file is shell independent. It is read every time a user logs in. It sets general variables,
such as the search paths (where it looks for programs), the terminal type (for how to show
characters on the screen), and the mail directory. This script executes after the shell-
specific startup (see below).
.profile
This file is read with every new shell that is opened. It is the equivalent of .login for each
individual shell, while .login sets its variables only once per login. This file is shell- independent.
.cshrc
This file gets read with the startup of every new csh. If /bin/csh is the selected shell for a user, the login program will start a csh after login and read in .cshrc. This file contains terminal type definitions, the prompt characterization, the variable which defines the standard editor, and aliases.

Shell Scripts
Shell scripts are files containing series of shell commands which can run both interactively and non- interactively. The file .cshrc is a good example of a simple csh script. The file /etc/rc.local is a more complex shell script. Many files in the directory /etc are shell scripts. Consult a few of them and the manual pages to get a sense of scripting.

IV. Basic Commands
                         After logging in to the Unix system (check with the ACC is you have questions about establishing your Unix account, logging in, or terminal emulation) and depending on your needs, a variety of commands are available for your use.
Shell Commands

passwd       - Sets or resets your login password.

logout, exit - Either one logs you out of the Unix system.

      who,    w      - Either one displays all users logged on the local host.  
                             w provides more information than who.
      <^z>               -  Suspends a job (see “Suspended Jobs” above).
    
ps              - Shows the processes that you are running on the system.
    –r-Shows only processes currently running.
    –a-Shows all user run processes (even those that are not yours).
    –u-Shows a detailed output of what processes are running.

V. Editors
The Haverford College Unix system has three main programs for editing files:
Pico 
          It is the simple, easy-to-learn editor that is supported by Haverford College. To learn more about using  Pico, please consult the ACC guide Using the Pico Editor.
Emacs 
          It is a very powerful and complex editor, which is widely used on Unix platforms.
vi – 
         the Unix VIsual editor – is the default editor on most Unix machines, and many functions in Unix use vi commands for inputs.


VI. Mail

                   The supported Unix mail program at Haverford College is Elm. This package is much easier to use than the standard Mail that comes with the Unix system. To learn more about using Elm, consult the ACC guide Using Elm for Unix Mail. 
elm: 
     Starts the Elm program; you can then use the inverse-video bar to select a message, and type    to read it.
The following commands work within Elm:
m - Send a mail message.
d - Delete the selected mail message.
r - Reply to the selected mail message.
f - Forward the selected mail message.
mail
       Starts mail and lists the first 20 unread messages. The standard mail program works on all Unix systems, though it is not as user-friendly as Elm. Since it can be used on any Unix system, it is useful to know how to get in and out of it, and some basic commands. 



VII. Networking
ftp node-
                   File Transfer ProtocolStanding  this is used to transfer files from one system to another by opening a connection to a node (a remote host). The node address can be entered either as an IP address (165.82.1.31) or a computer name (venus.haverford.edu). Opening a connection can also be done from within ftp by typing open   node. For file transfers from systems that you do not have an account on, the remote user name is usually “anonymous,” with your email address as the password.
The following commands work once a connection has been established:
cd  dirname        - Changes the current directory on the remote host. 
lcd dirname        - Changes the current directory on the local host.
binary               - Sets the transmission protocol to binary. This mode is required if transferring non-ascii programs, archives, or compressed files.

get   filename     - Transfers the specified file from the remote host to the local machine.  
      mget   wildcard-  Gets all files matching the given file pattern.FTP will prompt for each file name.

      put   filename    - Sends a file to the remote host. Certain restrictions and permissions apply.
      mput   wildcard- Sends multiple files (akin to mget).
      quit, <^d>      - Either one exits FTP. 
telnet        host        
                      Opens a connection to a remote host. The addressing scheme is equivalentto that of FTP. This protocol will allow full capacity logins, but not file transfers. The host name can be either an Internet address or a name.You should only telnet to machines that you have an account on, or that permit anonymous logins (such as Tripod).
 <^]>
                      Returns control to the local console.
  
finger
                      Looks at logins to a computer as specified. Without any options, fingershows who is presently logged into the system. With an option, fingergives login information about a user. It also tells when mail was lastchecked, and contains certain information that the user can place in hisor her .plan file.
          name 
        Gives information concerning the person with that username on the system where finger is run (due to privacy concerns, this feature is mostly disabled on the Haverford system).    
    @hostname
                 Gives information about the users presently logged into the indicated host.