Essential Linux and HTML
!
Computer Science for Bioinformatics, 140.636!
Unix Historical background
n Unix originally developed in late 60’s-70 at AT&T
Sources released to Universities where Unix caught on in CS departments. Notably UC Berkeley (BSD Unix)
n Linux (open source Unix) originally developed by Linus Torvalds
(Finland) and released under a GNU (free software) license ~1992.
n A host of fellow geeks found it cool and started to to help in the
development.
n Now a major operating system that is “free” as in “speech” & as in “beer”.
http://stein.cshl.org/genome_informatics/unix1/
Essential unix concepts
The file system
Devices e.g. Keyboard, printer screen, ethernet, mouse, etc. unix Kernel Shell
(accepts typed commands)
GUI
accepts point & click commands
Processes
e.g. editors, word processors,
spreadsheets, scripts, etc.
/
boot
bin dev etc home2 lib mnt opt proc root sbin tmp usr var vmlinux
140.636F08 faculty stu08-01 stu08-02 stu08-00 Stu08-03 bin local fernando private_html public_html home public example.txt
The hierarchical file system
The file system is a tree
Navigating the hierarchical file system
1. Navigation commands
n ls -- list directory contents
n pwd -- prints the absolute path to the working directory
n cd -- change directory to a directory specified by a path
n df -- free disk space
n du -- disk usage statistics
2. Paths
n Absolute path
n A fully qualified path must be specified from the root directory
n / is the symbol for the root directory
n Relative path
n Always defined relative to the current working directory
n . is the symbol that means the working directory
n .. is the symbol that means the directory above the working directory
n Executing an executable that resides in the current working directory
Review: commands to get around the file system
n pwd the command that tells you where
you are, i.e. print working directory
n ls the command that lists the contents !
of the current directory
n cd the command that changes the !
current directory. In other words !
it is how you move around the !
file system
Critical to memorize these three navigation commands!
Files permissions
n to see what permissions a file has use ls
command with -l option:
n ls -l filename
n to change file permissions use the chmod
command (see linux quickstart notes)
read write execute user
read write execute group
read write execute other
filetype
simple commands
n Command Syntax: command [options] parameters!
n Options
n An option is a way of telling Linux to perform a command in a particular way (like pressing alt-key while clicking a mouse)
n Typically a minus sign followed by one or more characters and sometimes an argument!
n Parameters
some example commands
wc hello1.sh
wc -l hellol.sh
wc -l *.sh
ls *.txt
Note the use of wildcards for simple filename patterns ? matches any single character
On-line help for commands
n
man
command
n
command
-help
Essential unix concepts
1. A process
Everything that “runs” under unix is a process, e.g. commands, spreadsheets,
terminal windows, etc.
Relevant commands: ps, top
2. A file & the hierarchical file system
directories(folders), data files, applications. On the disk, everything is a file. Even directories! Files are not processes!
Relevant commands: ls, df
3. A shell
A shell is a process. The shell accepts command lines and feeds them to the unix kernel. Command lines consist of commands or programs to execute along with information needed to execute them
4. Standard input/output
All processes have a standard input and a standard output
1. redirection 2. pipes
Processes
What processes am I running from my shells?!
ps
Which processes are using the most cpu?!
top
What are all processes running on the system?!
ps -A
What are all process that I am running?!
Standard input & output
two very important operating system concepts that you absolutely must understand
Standard I/O
n Commands are processes, so they have a default standard input and
a default standard output !
!
!
!
n For commands executed in shell window:
n standard input is connected to the keyboard
n standard output is connected to the screen
process
standard input standard output
shell process
STDIN STDOUT
When you invoke the Perl interpreter it is a process!
perl process
STDIN STDOUT
Redirection and pipes
two very important and related ideas that you absolutely must understand
Standard i/o streams can be
Redirected
n The standard output of a command can be redirected to
a file by the “>” redirector
ls process STDIN Storage device STDOUT graphics device ls -l results.txt STDOUT file ls -l > results.txt
Standard i/o streams can be
Redirected
n a file can be redirected to the standard input of a command by the
“<“ redirector. wc process STDOUT graphics device STDIN results.txt file wc -l < results.txt Keyboard device STDIN wc -l
a pipeline of processes
process1
file1.txt
STDOUT STDIN process2
file2.txt
a
“
pipeline
”
of processes
!
(
without the intermediate files)
Pipes
The standard output stream of one command can be piped to the standard input of another command by using the
pipe “|” symbol. No intermediate file is required.
Example: What does this do?
ls -l | wc -l
BASH
n BASH(Bourne Again SHell) is a Unix shell and
command language
n The syntax of the command language is: n <command> <options> <arguments>
n <command> is either a built-in command
(already in RAM) or the name of an executable file.
n An executable file is either a executable binary or
a text file (known as a script) that is interpreted by an interpreter (which could be BASH).
BASH
!
variables
n By convention environment variables are always
capitalized but in general variables needn’t be
n To see values of all environment variables use the
env command without an argument
n Values are set with ‘=‘ (no spaces)
n Values are instantiated with ‘$’
n Example:
MYVAR=“foo” echo $FOO
How the shell executes commands and applications
1. Search for a command
1. Is the command a built-in?
2. Is the command a file in the current working directory?
3. Is the command a file in one of the paths specified by the
PATH environment variable (demo)
2. Execute the first executable file that is found
3. The file must have “execute permission in order to be
executed, otherwise you will see a “permission error”
4. An executable file is either an application binary or a
n First line starts with ‘#!’ and tells bash where to
find the interpreter
n Remaining lines are statements in the language
that the interpreter understands
n Script must have execute permissions
Executable text files (scripts)
#!<absolute path to an interpreter> statements in interpreted language...
.
chmod u+x <script_name>
3 examples
echo “hello world!” #!/usr/bin/env perl
print “hello world!\n”;
#!/usr/bin/env python print (“hello world!”)
hello.sh hello.pl hello.py
env -- set environment and execute command, or print environment
How the shell executes a “script”
1. If the executable is a text file, the shell treats it as a
“script”. A script must have a special first line
1. The first line must start with #!, the rest of the first line is the
path to an executable interpreter 2. The interpreter is launched
3. The script file itself is passed to the standard input (STDIN)
of the the executing interpreter.
4. The interpreter skips over the first line because it starts with a
HTML (very) quickstart
Just enough HTML to get started on your homework. Goal of the first assignment: to be able to turn in the
Global structure of an HTML
Document
1. HTML version information 2. Header
3. Body
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN”
"http://www.w3.org/TR/html4/loose.dtd"> <HTML>
<HEAD>
<TITLE>My first HTML document</TITLE> </HEAD>
<BODY>
<P>Hello world!</P> </BODY>
Rudimentary HTML Syntax
and Rules
n Elements
n Tags come in pairs and describe content, e.g. <p>…</p>
<table>…</table>!
<img href=“jhsphlogo.jpg”> </img>
n Attributes
n parameters in tags that alter the behavior of the corresponding elements
n Example html file:
URLs
n Universal Resource Locatorsn <protocol>//<path>
http://www.cnn.com https://www.mtb.com
file:///users/sph140636/shared/homework1/index.html n To view homework template
n ssh into the cluster
n start firefox