Skip to content Skip to navigation

Connexions

You are here: Home » Content » Introduction to UNIX for Biologists

Navigation

Recently Viewed

This feature requires Javascript to be enabled.
 

Introduction to UNIX for Biologists

Module by: Quoclinh Nguyen, Masakatsu Watanab e. E-mail the authors

Summary: This module provides a description of UNIX for biologists who are not familiar with the UNIX environment.

Introduction to UNIX

What is UNIX?

UNIX is an operating system which like all other operating systems act as a master of ceremonies since their jobs are to accept and dispatch user commands and directing the system response to the appropriate place. UNIX is referred to as a multi-user, multitasking operating system, since multi users may each execute multiple commands simultaneously.

Note: There is an operating system called Linux. It is a free open-source operating system within the UNIX family. The difference between UNIX and Linux are almost invisible on a user-level. There are lots of commands transparent between the two systems. So you can learn about Linux from this session.

There are three main parts of the UNIX operating systems:

  • The kernel – the core of the program which is loaded up when you start.
  • The shell – the program where you enter your commands to the operating system.
  • The file system – where your files and data are stored.
Figure 1: Operating System
Figure 1 (img4-s.gif)

The UNIX Filesystem

The UNIX operating system is built around the concept of a filesystem which is used to store all of the information at constitutes the long term state of the system.

Every item stored in a filesystem belongs to one of four types:

  • Ordinary files: ordinary file contain text, data, or program information. Files cannot contain other files or directory. This is type of file that you usually work with.
  • Directory: directories are containers or folders that hold files, and other directories.
  • Devices: to provide applications with easy access to hardware. UNIX allows them to be used in much the same way as ordinary files. There are two types of devices in UNIX: block-oriented devices which transfer data in blocks (e.g. hard disk) and character-oriented devices that transfer data on a byte-by-byte basis (e.g. terminals)
  • Links: A link is a pointer to another file. There are two type of links - a hard link to a file is indistinguishable from the file itself. A soft link (symbolic link) provides an indirect or short cut to a file.

Typical UNIX Directory Structure

The UNIX filesystem is laid out as a hierarchical tree structure which is anchored at a special top level directory know as the rood.

Figure 2: Part of filesystem tree
Figure 2 (filesystem.jpg)
Directory        Typical Contents   

/                The “root” directory
/bin             Essential low-level system utilities
/usr/bin         Higher level system
/bin and /sbin   Hold system binaries. These are different 
                 from the program in /usr/bin in that they                        
                 are design as the basic program to run the 
                 the system.
/etc             hold system-wide configuration files. 
/var             hold log file, cache, and spool directories
/tmp             is meant for temporary storage by users.
/home            is a typical location of users.

Logging into (and out off) UNIX Systems

SSH or text-based (TTY) terminal:

When you connect to a UNIX computer remotely (client computer) or when you login locally using terminal, you will see the prompt:

login:

At this prompt, type in your username and hit enter or return key. You should be prompted for password:

login: bobcat
password:  your password won’t display on the screen as you type it in
	
If your username or password is incorrect, you will get an appropriate message from the computer and you will be presented with the login prompt again. Otherwise, you should be presented with a shell prompt which looks something like this: either $ or % or bobcat@computer’s name:
e.g bobcat@go:/>
Figure 3: Login to UNIX via ssh from Wondows Client (1)
Figure 3 (ssh-login.jpg)
Figure 4: Login to UNIX via ssh from Wondows Client (2)
Figure 4 (ssh-login2.jpg)

When you are ready to leave, you can log out by typing one of many commands:


bobcat@go:>exit
bobcat@go:>logout

Introduction to UNIX commands

Basic form is

command name option(s) argument(s)

Example 1


date                   - find out the date and time    
ls –l                  - list a directory with more information 
mv old_data  new_data  - Moving a file and renaming it
  • To display the on-line manual page about a command: man command_name

Typical UNIX Key commands


ls          List file – list files and sub directories in 
            the current directory
mkdir       Make directory
             e.g :/>mkdir music
cd          Change directory
pwd         Print working directory
rm          Remove (delete) a file
rmdir       Remove (delete) a directory
chmod       Change the permission of a file or dir.
man         Manual the help files
cat         Concatenate files or display them
more/less   Display files by screen
mv          Move or rename files or directories
head        Show the first few lines of a file
tail        Show the last few lines of a file
cmp         Compare two files, byte by byte.
diff        Compare to file, line by line.
grep        Matching a pattern     
            e.g :>grep ‘txt’ hello.txt
gzip        Reduces the size of one or more files
gunzip      Decompress file. It is equivalent gzip –d.
tar         Archive utility
             e.g :> tar cvf /home/bill <-- Creating
             e.g :> tar xvf /home/jack <--Extracting
ssh         Remort login program
Figure 5: >ls -lcommand list files and directories
Figure 5 (ssh-login3.jpg)

Useful Shortcuts

The UNIX shell provides very nice shortcuts. These make your life easier when working in the terminal.

History: The shell remembers all the commands you typed. You can scroll through your last commands with the arrow keys (Up and Down). Additionally, you can type history to list all commands you have been used.

bobcat@go:> history |grep -i keyword

Pipes: it let you use the output of one command as the input of another one.

Example 2


bobcat@go:> ls –l | sort
bobcat@go:> history  | more

File and directory permission

Every file or directory in a UNIX file system has three types of permission that define whether certain actions can be carried out.

  • read(r): A user who has read permission for a file may look at its contents or make a copy of it. For directory, read permission enables a users to find out what file are in that directory.
  • write(w): A user who has write permission for a file can alter or remove the contents of that file. For directory, the user can create and delete file in that directory.
  • execute(x): A user who has execute permission for a file can execute the contents of that file to be executed. For directory, execute permission allows a user to change to that directory.

For each file and directory, the read, write, and execute permission may be set separately for each of the following classes of users:

  • User(u): The user who owns the file or directory.
  • Group(g): Several users purposely lumped together so that they can share access to each other’s files.
  • Other(o): The remainder of the authorized users of the systems

Alternatively, specify permission by three-digit sequence. The first digit designates owner permission; the second, group permission; and the third, other permission. Permissions are calculated by adding the following octal values:

  • 4 Read
  • 2 Write
  • 1 Execute

Display information about files and directories by using ls command with –l option.


bobcat@go> ls –l myfile.java
-rw-r--r-- 1 bobcat users 198 2006-01-25 18:27 myfile.java
bobcat@go:> ls –l
-rw-rw-rw 1 bobcat users 198 2006-01-25 18:27 myfile.java

(to allow read and write permission for all users

Change group(chgrp): can be used to change the group that a file or directory belong to.


bobcat@go:> chgrp admin myfile.java
bobcat@go:> ls –l myfile.java
-rw-rw-rw 1 bobcat admin 198 2006-01-25 19:27 myfile.java

Working with Text Editor

Vi - Text Editor


bobcat@go:> vi filename <-- vi myfile.java
It will put filename into a buffer, and display the file on the screen. It the file is larger than the screen can display, the screen will act as a window into the file. At the beginning of a session, the screen will display the first part of the file.

If filename does not exist, vi will create it.

bobcat@go:> vi filename   <-- start the editor

Get in and out of vi

vi [filename] <-- Enter vi
[esc]:wq  <-- leave the editor and save the file
[esc]:q!  <-- leave the editor without save the file        

Figure 6: Using vi Editor
Figure 6 (vi.jpg)

Insert text mode

Hit [esc] key to return to common mode
  • i <-- for insert text to the left cursor
  • a <-- use to insert(append) text to the right cursor
  • A <-- insert(append) text to the end of current line
  • o <-- open new line for inserting text below cursor line
  • O <-- open a new line for inserting text above cursor line

Deleting and changing text mode

Hit [esc] key to return to common mode
  • x <-- deletes one character under cursor
  • 5x <-- another way to repeat the deletion command.
  • dw <-- deletes word under and to right of cursor.
  • dd <-- deletes the cursor line.
  • D <-- deletes from cursor to the end of line.
  • cw <-- changes word under and to right cursor to new text.
  • cc <-- changes current line to new text you enter.
  • s <-- substitutes character under cursor with new text.
  • S <-- substitutes current line with new text you enter.
  • r <-- replace character under cursor with new character..

Command to join two lines search keyword

Hit [esc] key to return to common mode
  • J <-- joins next line to the end of the cursor.
  • /keyword or /string <-- searches forward through text.

Quiz

Write a UNIX command line to do each of the following:

Exercise 1

Show the full pathname of the current directory:

Solution

...

Exercise 2

Show the online documentation for the “sort” command:

Solution

...

Exercise 3

Show how to allow the following access to the existing file ‘BIS141.txt’: all permissions for you, only read and write permissions for members of your group, and only read permission for other users:

Solution

...

Exercise 4

Rename the existing file, “UCMerced.txt”, to the new name, “UCM.text”:

Solution

...

Exercise 5

Copy the file ‘genome’ from your current directory to /usr/local/access:

Solution

...

Exercise 6

Delete all files in the directory /home/ucmerced/backup:

Solution

soon

Exercise 7

Delete the directory /home/ucm/backup:

Solution

...

Exercise 8

Show to change a working directory to /home/ucmerced/genome:

Solution

...

Exercise 9

Show the name, sizes, dates of all files in the current directory:

Solution

...

Exercise 10

Show the content of a zipped file, ‘ucmerced.zip’:

Solution

...

Exercise 11

Show the current date and time:

Solution

...

Exercise 12

Show how to logout from the current Unix/Linux session:

Solution

...

Answer the next questions about the text editor, vi.

Exercise 13

Write ONE command to initiate an insert mode:

Solution

i

Exercise 14

Write command(s) to delete a word:

Solution

...

Exercise 15

Write ONE command to save modifications and leave from the vi session:

Solution

...

Content actions

Download module as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks