Unix Basics

  1. Introduction
  2. History of Unix
  3. User Interface
  4. Unix File System
  5. File and Directory Manipulation
  6. Running Programs
  7. Printing from UNIX
  8. Miscellaneous Information

Introduction

What is Unix?

  • Unix is an operating system - meaning it is a program that acts as an intermediary between a user and the computer hardware. Windows NT is an operating system.
  • Unix is a Registered Trademark of AT&T.

Why is Unix so popular?

  • Multi-Tasking Capability - multiple jobs are executed by the CPU switching between them. The switching is done so frequently and quickly that the users may interact with each program while it is running. This increases the efficiency by allowing several jobs to complete in the time one would run on another system.
  • Development Environment -
    • When new development occurs in industry Unix can usually absorb it and still remain Unix.
    • Unix was written in the C programming language, which was developed to support Unix.
    • Unix was designed by programmers for programmers.
  • Independence of Vendor/Hardware - Unlike MacOS or Windows, Unix is not designed for specific machines or vendors. This makes it portable, and theoretically any program written under Unix can run on another Unix system.
  • Unix runs on personal computers, workstations, mini computers, mainframes and super computers. It can run on machines from the Apple Macintosh II to a Cray II.

History of Unix

  • Developed in 1969 at Bell Labs by Ken Thompson and Dennis Ritchie.
  • It was widely used within Bell Laboratories and spread to just a few universities.
  • The first version available outside of Bell Labs was in 1976, Version 6.
  • In 1978 Version 7 was released.
  • The Unix Support Group (USG) assumed administrative control and responsibility from the research group for distributing Unix within AT&T.
  • The first external distribution from USG was System III in 1982. It incorporated Version 7 and other Unix systems developed by groups other than Research.
  • Version 8 was later released, and contained a remote file system similar to NFS. This version also allowed multi user login.
  • System V, released in 1983, was the first version marketed aggressively. The USG was restructured as Unix System Development Lab (USDL).
  • In 1984 USDL released System V Release 2 (V.2). This version added virtual memory and shared memory.
  • The small size, modularity and clean design of Unix lead to much Unix-based work elsewhere: Rand, Harvard University, Purdue University, DEC and, the most influential of all non-Bell labs, University of California at Berkeley.
  • Unix software from Berkeley is released as Berkeley Software Distribution (BSD).
  • 1986 - 4.3 BSD Released.
  • 1988 - 4.3 BSD Tahoe released - included improved networking control and TCP/IP performance.
  • Version 10 was released by USDL in 1989 but it is only available in Bell Labs.
  • In an attempt to standardize all Unix flavors the POSIX (Portable Operating System Standard for Computer Environments) standard was created. Under these standards eventually there will be only one programming interface to Unix.
  • The first merged Unix was in 1989, called System V Release 4. System V R.4 combined System V, 4.3 BSD and SunOS. This new Unix conforms to the published POSIX standard, POSIX.1.
  • The last Berkeley release, 4.4 BSD, was finalized in June 1993. It is POSIX Standard Compliant and includes an implementation of Sun's NFS. Sun Microsystems helped to popularize BSD Unix by shipping it on their workstations.

A wide variety of Unix systems have been created. All of these go under a different name than Unix (since it is a registered trademark), but they are Unix operating systems.

  • HP uses HPUX.
  • Microsoft rewrote Unix for the 8088 family and called it Xenix. Windows NT was heavily influenced by Unix as well.
  • Sun Microsystems uses SunOS.

User Interface

Before using the user interface; a telnet client, such as PuTTY, must be configured to connect to the Missouri S&T Campus machines.

You will need:

Unix File System

Unix uses a Hierarchical Directory Structure with Tree Structured Directories.
This allows users to have non-unique file and directory names within their own directory structure. (Directories on the same level must have unique names, and files in the same directory must have unique names).
This also allows for non-unique names across user accounts. If this was not the case, every file name would have to be unique for the whole system, not just for an individual user.

 

What is a Unix File?

  • File format is a string of bytes.
  • Types of Files
    • Ordinary - text or binary files
    • Directory - directory information is stored in a file.
    • Special - linked files.

 

Where Your Account is Located

  • The login process will take you directly to your home directory. You will not have to find your directory after logging in, you are already there.
  • The absolute path to your home directory is /nethome/users/  <userid> ( <userid> is your SSO User ID).

 

Types of Pathnames

Unix has 3 types of paths that will get you to a specific file/directory.

Absolute Paths

  • All begin with a forward slash, '/'
  • Are fully specified addresses from the root directory
  • Example: /nethome/users/ <userid>

Relative Paths

  • All pathnames that do not start with a forward slash '/' or a tilde '~' are relative paths.
  • Relative means it is relative to the current directory.
  • Example: A file in your home directory would just be the filename.
  • Example: A file in a subdirectory off of your home directory would be subdir/filename.

User Relative Paths 

  • All pathnames begin with a tilde '~'
  • Your home directory would be   ~<userid>
  • To change to another user's directory you can specify it as,  ~  joeuser instead of /nethome/users/ joeuser
  • Everything using user relative paths is relative to the specified users home directory. It will not matter what your current directory is if you use user relative paths.

Unix Special Files

Unix creates two special files in each directory. These are useful when navigating around the filesystem and when referring to files.

  • The file . refers to the current directory. It is commonly used to refer to executables in the current directory, e.g ./a.out.
  • The file .. refers to the parent directory. It is commonly used to navigate up the filesystem, e.g. cd ..

File and Directory Manipulation

  • To Create a Directory
    • mkdir  <directory name> - Makes a directory named   <directory name>
  • To Remove a Directory
    • rmdir   <directory name>  - Deletes a directory named   <directory name>
  • To Change Directories
    • cd - cd alone will take you to your home directory
    • cd  <directory name> - Takes you to a directory named   <directory name>
  • Find Current Directory
    • pwd - Print Working Directory

 

List the Contents of a Directory:

Unix does not have a 'dir' command. There is a command ls which lists the contents of a specified directory. lt has many options to make viewing the information easier.

  • ls - lists just the file names and sub-directory names in the current directory.
  • ls   <directory name> - lists just the file names and the sub-directory names in the specified directory.
  • Use the online manuals to obtain the remainder of the ls options: man ls.
    • ls -l - lists the long format of the directory information.
      • drwxr-xr-x 18 joeuser ssouser 4096 Jul 11 20:20 OldFiles
      • -rw-r--r-- 1 joeuser ssouser 726 Sep 13 1993 READ.ME.NEW.SSO.USER
    • ls - a - lists all the files and directories in the specified directory. This includes the dot (.) files (system files), which do not appear in a ls command.
    • ls -al - lists the long format of all the files and directories, including the system files.
    • ls -F - lists the directory names and executable files only.
    • ls -R - recursively list files in all subdirectories, not just the subdirectory names.

 

File Manipulation

  • To copy files :
    • cp file1 file2
    • cp file(s) dirname
  • To rename files :
    • (Unix does not rename, it moves from one filename to another) mv oldname newname
  • To move files to a different directory.
    • mv file directory
    • mv file(s) directory
  • To remove (delete) files:
    • rm filename
    • rm file1 file2 .. fileN
    • rm -f filename - forced removal of a file
    • rm -i filename - interactive query before removal
    • rm -r filename - recursive delete - dangerous.
    • rm -rf dir(s) file(s) - recursive force - CAREFUL!!!

 

To Edit Files in Unix:

  • pico editor: 
    • This editor is the most user friendly of the Unix file editors. There are no special codes to type in text, and a command menu is available at the bottom of the screen. This editor also has a primitive spell checker.
    • Syntax: pico filename
    • The filename can be an existing file you want to edit, or a new file you want to create.
  • vim editor: 
    • This editor was designed for programming in the Unix environment. It is neither intuitive nor user friendly. It is difficult to use if you have not used the editor before. There is an insert and a command mode (typing can only be done in the insert mode).
    • Syntax: vim filename
    • The filename can be an existing file or a new file

 

Creating New Files in Unix

  • When creating new files remember Unix is case sensitive. A file named 'Test' will be different from the file 'test'.
  • File names can be 1 to 255 characters long.
  • File names may contain A-Z, a-z, 0-9, a period ., underscore _, or a dash -.
  • Try to avoid blanks, tabs, asterisks *, question marks ?, parentheses (), brackets [], braces {}, angle brackets <>, pipes |, slashes /\, or any control characters. These may cause problems because of complications with the Unix shell. File names containing these characters are usually hard to create, but not impossible.


Viewing Files without Opening

  • cat filename - concatenates and print. This will print out the contents of the file to the screen.
  • cat file1 .. fileN - Concatenate and print. This will concatenate several files together and print to the screen.
  • more filename - displays files one page (screen) at a time. Keeps one line of text from the previous screen.
  • page filename - displays files one page (screen) at a time. Does not keep any old text. Clears the screen before each new screen.
  • for both page and more:
    • spacebar - will advance to the next full screen.
    • carriage return - advances one line.
    • /pattern carriage return - finds next occurrence of the pattern in the file.

Disk Space

  • Disk space is shared on Unix. You are given a 50 GB allotment, initially, at Missouri S&T.
  • To determine amount of disk quota used
    • Run the command du -hs
    • This will output the amount of space your files are consuming.
  • If you receive disk space errors, or you can not write out files to your account, check your %Used. If you are close to 100% (depending on the size of the file you want to save), at 100% or over 100%, then you will not be able to write out any more information until some files are removed or the disk quota increased.
  • Certain types of files are unusually large and may be the bulk of a disk space problem. Postscript files and graphics files are normally the largest space users. This includes graphics for the World Wide Web.
  • "core" files can also take up several megabytes of space. These files are generated by programs that crashed and created the core file for debugging purposes. The core files should be removed, they are not needed by users.

Running Programs

  • Under Unix users can run more than one process (program) at a time. You don't have to wait for one to complete to begin the next. This is called multi-tasking. It is done with time slices handed out to each process by the CPU.
  • Programs that are not interactive, meaning they do not prompt the user for input from the terminal/window, can be run in the background. By running a program in the background you still have a prompt that is usable, but the process will run to completion while you continue to work on other things.
  • To put a process (program) in the background, attach an ampersand at the end of the command.
    Example : ls -al&
  • When a background process ends you will receive a message to your terminal the next time you hit return.
  • To regain interactive control of a background process, bring the process to the foreground with the command fg.
  • To interrupt a command (or a process) issue the kill character : control+c.
    This will halt a process that was running in the foreground only. By pressing the control key and the c key at the same time you will send the command interrupt message to the current process. This is useful for exceptionally long directory listings that you want to halt, or runaway programs.

Printing from UNIX

There are two types of printing commands for Unix. One is lp and the other is lpr.
Commands:

  • To show the default printer : lpstat -d most will be set to mcs116dist
  • To print to the default printer : lp filename
  • To print to a specific printer : lp -d printer filename

if no file name is given for either of the lp commands then standard input will be assumed.

Miscellaneous Information

There are several Unix commands that can make working under Unix easier.

  • date - prints the date and time.
  • who -prints a list of users logged in currently.
  • who am i - prints just who you are.
  • whoami - prints just your SSO User ID.
  • w(under BSD Unix only) - lists users currently logged in and what they are doing.
  • finger ssouserid - provides user information : name, last login time, etc.
  • man command - prints out the manual page for the specified command.
  • man -k keyword - prints a list of the commands containing that keyword.