http://creativecommons.org/licenses/by-sa/2.0/
Tutorial 2.1
1
Unix Tutorial 2.1a
Mike Wilson
Tutorial 2.1
2
Unix tutorial 2.1a
1. Review of some essential UNIX commands
1. Hands on demo of cat, grep and du
2. Getting into your shell
3. A few more commands
4. Using sim4 to align cDNA to genomic
sequence
5. Time to play!!!! Time to play: open up your
laptops
Tutorial 2.1
3
A review of the essential
•
•
•
•
•
•
•
•
cd
ls
cp
mv
rm
mkdir
rmdir
pwd
Tutorial 2.1
– change directory
– list
– copy a file
– move or rename a file
– remove a file (use caution)
– make a directory
– remove a directory (must be empty)
– print working directory
4
Redirecting and reading files
• cat can be used to display file contents
• cat is also used to concatenate files
1) Move to unixtutorial directory
2) Type: cat bka.txt unix.txt > both.txt
– Copies contents of bka.txt and unix.txt into one
file called both.txt
– Note that if you already had a file called both.txt
it would be overwritten!
– Type less both.txt to read the file
3) Type: cat unix2.txt >> both.txt
– Appends unix2.txt to both.txt
Tutorial 2.1
5
Grep
• grep = global regular expression print
• grep is powerful for searching file names and contents
• grep [options] regexpression [files]
– grep –e [vfy][fyw].*[gstne][gstqcr][fyw].*p filename
• searches for this pattern in filename
• -e option indicates expression pattern;
• [ ] one of any of the character
• .* zero, one or more of any character
• Goal: use grep to look for fun in one of your files
1) Go to unixtutorial directory if you aren’t there already
2) Type: grep fun both.txt
• Looks for “fun” in the file “both.txt”
• Did you find fun?
• Are you having fun?
Tutorial 2.1
6
Print disk usage: du
• du [options] directory
– du by itself prints current directory and all subdirectory names and sizes
– du –a prints information for all files as well
• Du you want to find a file?
– du –a | grep filename
– you can of course search for partial filenames with
your wild cards/arguments etc.
– go to home and look for unix.txt
Tutorial 2.1
7
Shell files and aliases
• A buffer between you
and the operating
system
• Bourne-again shell
(BASH) is the standard
Linux shell (from GNU)
• The shell is interactive,
it allows you to
customize your Linux
session as well as
program
Tutorial 2.1
8
Common Shell symbols
•
•
•
•
•
•
•
•
•
>
>>
<
|
&
*
?
[]
\
Tutorial 2.1
redirect output
append output
redirect input
pipe output
run process in background
match any characters in filename
match single character in filename
match any characters enclosed
quote following character
9
Customizing your shell
• Special BASH files you will find in your home
directory
.bash_profile
executed at login
.bashrc
executed at shell startup
.bash_logout
executed at logout
.bash_history
contains your previous commands
• Type: ls –al to see all your files
• Customizing your shell usually will involve editing
the .bashrc file
Tutorial 2.1
10
Aliases: making HOME feel like home
• aliases can make
your life easier
• typing alias will
reveal ‘default
aliases’
• you can add
temporary aliases
• alias lf=‘ls –F | less’
• unalias will remove
this: unalias lf
• you can add
permanent aliases
to your .bashrc file
Tutorial 2.1
11
I don’t know much about history
• Scroll through your history with
• Look at your history file by typing history
• history lists your previous commands next to a
number.
• you can rerun any given number by typing !n
• !55 would re-execute command 55 in my history
• It’s worth learning more about history
Tutorial 2.1
12
Environment variables
• Environment variables are settings that control specific
aspects of the system
– each program has its own variables
– the shell (a program we spend a lot of time with) has variables
too
– you can look at all your shell environment variables by typing set
Some common environment variables for the shell
• HOME
– points to the home directory
• PATH
– places that the shell will look for your commands
• PS1
– determines what is displayed at the command prompt
Tutorial 2.1
13
Customizing environment variables
• variables can be used in commands and
filenames by preceding them with a $ sign
– i.e. $HOME/unixtutorial/unix.txt
• you can use $PATH in a command to add a
new directory to your PATH
– export PATH=$PATH:$HOME/unixtutorial
export makes
shell variable
PATH global
$PATH
refers to
current path
: separates
current PATH
from new one
new PATH to be
added
– this appends the new PATH to the existing one
– to view your PATH: echo $PATH
Tutorial 2.1
14
Editing .bashrc with emacs
– make your changes to the PATH memorable by editing
.bashrc
• open .bashrc in a text editor (emacs or gedit or vi)
• add PATH=$PATH:$HOME/unixtutorial
Tutorial 2.1
15
Installing programs in Linux/Unix
• Unix and Linux comes with many applications preinstalled
• You will likely want to install more
• This can sometimes prove to be difficult for a few reasons some of
which inlcude:
– what flavour of unix/linux you are running
– what privledges you have as a user (i.e. root)
– the nature and quality of the program you want to install
• Much softwares builds upon previous work, programs, libraries etc.
• Sometimes you need to find and install these yourself.
• Depending on the nature of the program and implementation this
can become a really annoying scavenger hunt.
• The art of installation can take patience and practice
Tutorial 2.1
16
Implementation energy
– situation A
• some energy needed to install
and learn new program
• energy is regained from the time
saved obtaining results
– situation B
• energy spent installing and
learning program is more than
time/energy saved
– Experience takes energy and time
(so everything may look like a B
when you start)
– Even experience may not make up
for time wasted implementing a
poorly written or compiled program
Tutorial 2.1
17
Making and breaking tar files
• File is now filename.tar
– Tar is short for tape archive
– It is mostly used to bundle files and directories
• To untar a tar file
– Type: tar -xvf filename.tar directoryname
– When extracting make
c
Creates (a new tar file)
sure the directory you
x
Extracts (a tar file)
choose is where you
f
Files
want the files
(could be messy)
v
Verbose (lets you see files created)
z
Use (tar -xzvf) to uncompress and untar
in one step
• Create a tar file of everything inside of a directory
– Type: tar -cvf filename.tar directoryname
Tutorial 2.1
18
Un/compressing files
• Most UNIX software you download will be
compressed and bundled.
• These files often look like: filename.tar.gz
– To uncompress type: gunzip filename.tar.gz
– File is now filename.tar
• To compress a file type: gzip filename
– You then get a smaller file named: filename.gz
Tutorial 2.1
19
A process is a program in action
– To suspend a process type: control z
– Situation:You are working on a buffer in emacs and
want to get back to the command prompt without
closing emacs
– type: control z
• emacs is suspended and you are back at the command prompt
• You can type ps to see what processes are running
– Now type: fg
• You are back in emacs working on your buffer
– If you type bg it will run the process in the
background (as opposed to suspending it)
– somtimes you may want to run a process in the
background from the start. Use &
• mozilla &
Tutorial 2.1
20
A process is a program in action
– To check out the action type: ps
– To put a stop to the action type:
kill processnumber
• You can also can use the command top to manage processes and
check memory usage etc. (more powerful than ps)
•In top
–Type u and then enter your username to see processes you
are running
–Type k and enter process ID to kill a program
–Type q to leave top
Tutorial 2.1
21
Sim4- A Computer Program for Aligning a
cDNA Sequence with a Genomic DNA
Sequence. (Florea et al 1998)
• Align cDNA, EST data with genomic sequences
• Uses BLAST based technique finds “exon cores” of a given word size.
• Takes into account conventional splicing logic and possibility of
sequencing errors.
• Sim4 is a useful, efficient and commonly used bioinformatic program
• It’s also well documented and easy to install. Try it at home or work!
• Usage:
– sim4 seqfile1 seqfile2db {[WXKCRDAPNB]=value}
– sim4 my_genomic my_cDNA_list K=15 C=11 A=3 W=10
• For the rest of the lab you will use sim4 to do some bioinformatic work
and get to know your shell
Tutorial 2.1
22
Sim4
•You can see the parameters of sim4 by typing:
sim4
•We will use default parameters but you will have to look
at the instructions (its important to do this for all
bioinformatic programs).
• A basic sim4 run will look like:
sim4 genomic_sequence list_of_cdnas A=3 > outfile
Tutorial 2.1
23
A little aside about the Linux mascot
Tux
• Some people have told me
they don't think a fat penguin
really embodies the grace of
Linux, which just tells me
they have never seen a
angry penguin charging at
them in excess of 100mph.
They'd be a lot more careful
about what they say if they
had.
-- Linus Torvalds
Tutorial 2.1
24
Unix Tutorial- when you have had
enough
Tutorial 2.1
25
A few more
Resources
• http://www.gnu.org/software/bash/
manual/bash.html
– The official BASH manual from
GNU
• http://linux.org.mt/article/terminal
– excellent tour of the BASH
shell!
• http://www.tldp.org/
– the linux documentation
project. Great resource
• http://globin.cse.psu.edu/globin/ht
ml/docs/sim4.html
– info about and download sim4
Tutorial 2.1
26
The last resources- have fun!
Tutorial 2.1
27
© Copyright 2026 Paperzz