Download presentation
Presentation is loading. Please wait.
Published byCandace Boyd Modified over 9 years ago
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 adapted from a variety of sources including material found on the Web; the copyright symbol, ©, on copyrighted material has been retained.
2
Basic Unix Mark A. Pauley © 2004 - 2011 2 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
3
Basic Unix Mark A. Pauley © 2004 - 2011 3 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.
4
Basic Unix Mark A. Pauley © 2004 - 2011 4 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
5
Basic Unix Mark A. Pauley © 2004 - 2011 5 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
6
Basic Unix Mark A. Pauley © 2004 - 2011 6 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
7
Basic Unix Mark A. Pauley © 2004 - 2011 7 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.
8
Basic Unix Mark A. Pauley © 2004 - 2011 8 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.
9
Basic Unix Mark A. Pauley © 2004 - 2011 9 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
10
Basic Unix Mark A. Pauley © 2004 - 2011 10 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,...
11
Basic Unix Mark A. Pauley © 2004 - 2011 11 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)
12
Basic Unix Mark A. Pauley © 2004 - 2011 12 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
13
Basic Unix Mark A. Pauley © 2004 - 2011 13 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.)
14
Basic Unix Mark A. Pauley © 2004 - 2011 14 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.
15
Basic Unix Mark A. Pauley © 2004 - 2011 15 Unix Directory Structure Different flavors of Unix (including Linux) have a fairly consistent directory structure. root (/) binetcvartmp continentsoceans bats marsupials bandicoot kangaroowombat dev homeusr jack jill opossum wombat
16
Basic Unix Mark A. Pauley © 2004 - 2011 16 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.
17
Basic Unix Mark A. Pauley © 2004 - 2011 17 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
18
Basic Unix Mark A. Pauley © 2004 - 2011 18 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.
19
Basic Unix Mark A. Pauley © 2004 - 2011 19 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).
20
Basic Unix Mark A. Pauley © 2004 - 2011 20 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.
21
Basic Unix Mark A. Pauley © 2004 - 2011 21 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
22
Basic Unix Mark A. Pauley © 2004 - 2011 22 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.
23
Basic Unix Mark A. Pauley © 2004 - 2011 23 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
24
Basic Unix Mark A. Pauley © 2004 - 2011 24 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)
25
Basic Unix Mark A. Pauley © 2004 - 2011 25 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.
26
Basic Unix Mark A. Pauley © 2004 - 2011 26 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.
27
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 Mark A. Pauley © 2004 - 2011 27
28
Basic Unix Mark A. Pauley © 2004 - 2011 28 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.
29
Basic Unix Mark A. Pauley © 2004 - 2011 29 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,
30
Basic Unix Mark A. Pauley © 2004 - 2011 30 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
31
Basic Unix Mark A. Pauley © 2004 - 2011 31 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.
32
Basic Unix Mark A. Pauley © 2004 - 2011 32 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
33
Basic Unix Mark A. Pauley © 2004 - 2011 33 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.
34
Basic Unix Mark A. Pauley © 2004 - 2011 34 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.
35
Basic Unix Mark A. Pauley © 2004 - 2011 35 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.
36
Basic Unix Mark A. Pauley © 2004 - 2011 36 Working with Files: rmdir remove (empty) directory SYNOPSIS rmdir [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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.