36
Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content adapted from a variety of sources including material found on the Web; the copyright symbol, ©, on copyrighted material has been retained.

Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Embed Size (px)

Citation preview

Page 1: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Bioinformatics Spring Break Workshop

Basic Unix

Disclaimer: This set of slides is for educational use only. It contains original content as well as content adapted from a variety of sources including material found on the Web; the copyright symbol, ©, on copyrighted material has been retained.

Page 2: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 20112 Basic Unix

Why Learn Unix?

Many high end-client server systems are Unix based; Unix/Linux skills are much in demand (job skills).

Excellent software-development platform

Much of the software is free (unique culture)

You are an engineer, a mathematician, a scientist, a movie producer: many fields are Unix-centric; i.e., a working knowledge of Unix is required.

Most really exciting Computer Science stuff is done on Unix systems (personal growth).

A good way to learn fundamental computer OS concepts (files, processes, etc.).

A understanding of Unix can Impress your friends Make new friends Destroy and utterly crush your enemies

Page 3: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 20113 Basic Unix

Unix Advantages

It is very popular, so it is easy to find information and get help Pick up books at the local bookstore Plenty of helpful websites Most Computer Science students know Unix

Can run on virtually any computer (IBM, Sun, Compaq, Macintosh,etc)

Free or nearly free Linux/open source software movement RedHat, FreeBSD, MKLinux, LinuxPPC, etc.

Page 4: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 20114 Basic Unix

Unix Advantages (cont.)

Very stable – computers running Unix almost never crash

Very efficient Gets maximum number-crunching power out of your processor (and

multiple processors) Can smoothly manage extremely huge amounts of data Can give new life to otherwise obsolete Macs and PCs

Page 5: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 20115 Basic Unix

Unix Disadvantages

Unix computers are controlled by a command line interface Not user-friendly Steep learning curve; takes a long time to truly master

Hackers love Unix There are lots of security holes – although probably not as many as

Windows () Most computers on the Internet run Unix , so hackers can apply the

same tricks to many different computers

Different flavors of Unix have subtle, and sometimes not-so-subtle, differences

Page 6: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 20116 Basic Unix

Unix Help on the Web

Some online Unix tutorials (there are many more): Unix for Beginners

http://www.ee.surrey.ac.uk/Teaching/Unix/ A basic Unix tutorial (Idaho State University)

http://www.isu.edu/departments/comcom/unix/workshop/unixindex.html Unix Guru Universe

http://www.ugu.com/sui/ugu/show?help.beginners Getting Started With The Unix Operating System (Leeds, UK)

http://www.leeds.ac.uk/iss/documentation/beg/beg8/beg8.html

Page 7: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 20117 Basic Unix

General Unix Tips

Unix is case sensitive!! myfile.txt and MyFile.txt would be different files ls and LS (if it existed) would be different commands

Every program is independent The core operating system (known as the kernel) manages each

program as a distinct process with its own little chunk of dedicated memory.

If one program runs into trouble, it dies, but does not affect the affect the kernel or the other programs running on the computer.

Page 8: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 20118 Basic Unix

The Unix Shell

You communicate with a Unix computer through a command program known as a shell.

The shell interprets the commands that you type on the keyboard.

There are actually many different shells available for Unix computers, and on some systems you can choose the shell in which you wish to work.

You can use shell commands to write simple programs (scripts) to automate many tasks.

Page 9: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 20119 Basic Unix

Unix Shells

Many shells to choose from...

sh: The Bourne Shell The original Unix shell S.R. Bourne designed it at Bell Labs Not very "user friendly”, but good for programming sh or a reasonable facsimile comes packaged with virtually every

Unix system

csh: The C-shell A shell whose syntax is more “C”-like Command history and job control

Make it very popular as a CLI Comes with most Unix systems

Page 10: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201110 Basic Unix

Unix Shells (cont.)

tcsh: The T C-Shell Updated C-shell with better “line-editing”, access to command

history, and command and filename completion

bash: The Bourne Again Shell Aimed at providing a public domain version of the Bourne shell Default shell for Linux Implemented as a part of GNU project by public efforts

ksh, zsh, tsh, ...

Page 11: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201111 Basic Unix

Unix Commands - exit and passwd

Unix commands are short and cryptic; e.g., vi, rm. Computer geeks like it that way; you will get used to it.

Two commands of immediate interest exit - exit the shell (log off) passwd - Changes your password (follow the prompts)

Page 12: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201112 Basic Unix

In-class Practice

Now you try! Change your password to something different (the system will

enforce certain rules). Exit the system and log back in

Page 13: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201113 Basic Unix

The Unix Directory Structure

Windows, MacIntosh use the concept of folders.

Unix uses the concept of directories

Both are hierarchical (folders can have subfolders, directories can have sudirectories, etc.)

Page 14: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201114 Basic Unix

The Unix Directory Structure (cont.)

Directory terminology: Home directory

Where your files live. You always go there when you log in.

Working directory Whatever directory you are currently in.

Page 15: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201115 Basic Unix

Unix Directory Structure

Different flavors of Unix (including Linux) have a fairly consistent directory structure.

root (/)

bin etc vartmp

continents oceans bats marsupials

bandicoot kangaroo wombat

dev home usr

jack jill

opossumwombat

Page 16: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201116 Basic Unix

Typical Directories

bin: Software for the shell and most common Unix commands.

dev: Short for devices, holds the software necessary to operate peripherals such as printers and terminals.

etc: Contains various administrative files such as lists of user names and passwords.

home: Contains the home directories of users.

tmp: A directory used to hold temporary files.

var: Files that contain information that varies frequently; most commonly, mail directories.

Page 17: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201117 Basic Unix

Unix Commands - pwd, ls and who

More useful commands: pwd – Prints the working directory ls – Lists the contents of the current directory who – Lists the users currently on the system

Page 18: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201118 Basic Unix

In-class Practice

Now you try! Print out your current directory – You should get something like /home/mpauley

List the files in the current directory – Your current directory should appear empty.

Determine who is currently logged into the system. Find your login, and a neighbor’s, in the list.

Page 19: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201119 Basic Unix

Moving Around

Move around the directory structure using the command cd.

Basic syntax: cd [dir]

dir can be either relative or absolute.

Directory “abbreviations” ~ Your home directory

Use cd ~ to return to your home directory .. The parent directory; the directory “one up” from the current

directory. Use cd .. to move to the directory “one up” from the current directory.

. The current directory

Shortcut Use cd - to return to the previous directory (where you just were).

Page 20: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201120 Basic Unix

Creating Directories (mkdir)

mkdir = (make directory)

Creates a directory. mkdir [new directory name] mkdir calendar

Inverse command is rmdir (remove directory) – Directory must be empty.

Page 21: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201121 Basic Unix

In-class Practice

Now you try! Navigate to / Return to your home directory Navigate to /usr. How many subdirectories are there? Return to your home directory Navigate to /usr/local/bin. How many subdirectories are

there? Return to your home directory. Create a directory called tmp in your home directory Verify that you created the directory (use ls) Remove the tmp directory Verifying that you removed the directory

Page 22: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201122 Basic Unix

Unix Text Editors

What is a text editor? Like a word processor but it does not apply formatting styles (bold,

italics, different fonts, etc.).

Several text editors installed on hal: nano – Easy! (the one we’ll start with) emacs – A heavily-featured editor commonly used in programming vi/vim – Another heavily-featured editor commonly used in

programming

Which text editor is “best” is a holy war. Pick one and get comfortable with it.

Page 23: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201123 Basic Unix

Unix Text Editors: Design concepts

Editors in Unix come in two general flavors: Modal editors have “modes”

Generally have input and command modes Input mode allows entry of text Command mode allows positioning within the file and more

sophisticated text modification Unix examples: ed and vi

Modeless editors Have only one mode Positioning and text manipulation are done by special key sequences

(like arrow keys and function keys) Could also be done by mouse actions or menus Unix examples: emacs and nano

Page 24: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201124 Basic Unix

Starting nano

Basic syntax: nano [FILE] [FILE] can be an existing file. if [FILE] does not exist, it will be created.

The nano window: commands at the bottom, text area at the top (^ stands for the Ctrl key)

Page 25: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201125 Basic Unix

nano Navigation

Use arrow keys, otherwise: Ctrl-f: move forward a character. Ctrl-b: move backward a character. Ctrl-n: move to the next line. Ctrl-p: move to the previous line. Ctrl-v: move forward one page. Ctrl-y: move backward one page.

Page 26: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201126 Basic Unix

nano Editing

Inserting Just type.

Deleting Ctrl-k: deletes (cuts) the current line of text.

Use Ctrl-k repeatedly until all the lines you want to cut have been deleted (lines are stored in a buffer)

Ctrl-u: uncuts (i.e., pastes) the last cut text. Pastes all of the lines in the buffer. Use Ctrl-u repeatedly to simulate copy and paste.

To save your work Ctrl-o (writeOut)

To exit: Ctrl-x If you haven’t yet saved your file, you will be prompted to do so.

Page 27: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201127

In-class Practice

Now you try!! Using the nano text editor, create a file (myInfo.txt) that contains the

following information (one per line; start each line with “My name is. . .”, etc.)

Your name Your age The school you go to What year of school you’re in (freshman, etc.) The classes you are taking this year/semester/quarter. Your career goals.

Basic Unix

Page 28: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201128 Basic Unix

Command Terminology

Most Unix commands have options and/or arguments – specifies the behavior of the command

Argument Entered at the end of the command line Usually a file on which the command will act

cat –n myGene.seq(myGene.seq is the argument)

Options Entered between the command and its argument

Short options – Generally single letters and prefaced with a single hyphen; may be grouped

Long options – Prefaced with a long hyphen; cannot be grouped.

Case sensitive – In Unix, uppercase and lowercase letters are different.

Page 29: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201129 Basic Unix

Command Modifiers (cont.)

In the SYNOPSIS section of a man page [] Optional option/argument | Options are mutually exclusive ... Option/argument may be repeated

From its man page, ls has a number of possible options and one (optional) argument; nothing is mandatory,

Page 30: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201130 Basic Unix

Options for ls

Useful options for ls -a, --all Do not hide entries starting with . -F --classify Append indicator (one of */=@|) to entries -l Use a long listing format -g Like -l, but do not list owner [FILE] Information about just a particular file.

Examples: ls -a List all the files in the current directory ls -aF or ls -a -F List all the files in the current directory,

appending an indicator ls -al List all the files in the current directory in long format. ls -al cat.txt List long format information for the file cat.txt

Page 31: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201131 Basic Unix

Viewing a file (without a editor)

What if you want to view the contents of a file (but not edit it)?

Use the cat command cat [name of file] Displays the contents of the entire file (bad for long files)

Use a pager more [name of file]

Use return key to view the next line of text Spacebar to read the next page of text q to quit / to search.

less [name of file] Like more but better Arrow keys to navigate by line u to move up a page. A useful option is -N, which numbers the line in the files.

Page 32: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201132 Basic Unix

In-class practice

Now you try! Practice using the different option for ls. Read the man page for cal

What does cal do? What does the -3 option do? What does the -m option do?

Display the contents of files in your public_html directory using cat less

Page 33: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201133 Basic Unix

Working with Files: cp

copy (vowels in a command are often omitted)

Copies the contents of one file to another. cp [file to copy] [new file name]

Flags -r: will copy directories and all their contents. Without this flag, the directory will not be copied and you will get an

error message.

Page 34: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201134 Basic Unix

Working with Files: mv

move

Better name could be the rename command.

Changes the name of a file. mv [old file name] [new file name]

If the two files are in different locations, then the effect is that the file is moved from one directory to another.

Note, if [new file name] is a directory, you will move [old file name] to that directory and keep the original name.

Page 35: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201135 Basic Unix

Working with Files: rm

remove - Deletes the specified file or files

SYNOPSIS rm [OPTION]... FILE...

Destructive! The file(s) are gone and cannot be retrieved.

Note: use rm –rf to remove a directory and all of its contents.

Page 36: Bioinformatics Spring Break Workshop Basic Unix Disclaimer: This set of slides is for educational use only. It contains original content as well as content

Mark A. Pauley © 2004 - 201136 Basic Unix

Working with Files: rmdir

remove (empty) directory

SYNOPSISrmdir [OPTION]... DIRECTORY...

Deletes a directory (as opposed to the rm command which deletes a file).

The directory must be empty otherwise you will get an error.