introduction to the linux operating system what is linux
TRANSCRIPT
Sam
an A
lavi-
2016
Introduction to the Linux Operating System
• Linux is a free and open source operating system for
computers
• Has wide usage in web servers. i.e. Google farms
• Popular in scientific computing and simulation community, In 2014 97% of
world’s fastest 500 computer systems run Linux!
• Developed in the 90’s and for most users it is very similar to Unix.
• Linux has many variants or ‘distributions’ because it is open source
• Most molecular simulation programs or packages run on Linux
Assignments require use of Linux
Linux Mascot
What is Linux
1 Acknowledgment: These lecture notes are based on notes of Prof. Tom Woo
Sam
an A
lavi-
2016
Sam
an A
lavi-
2016
2
Computers in the Montpetit 142 Lab
1. The account you use to logon will be your uOttawa account
(Exchange email account).
2. You will have access to an H drive, the home drive on the uOttawa
environment. However, it is recommended that you copy any files you need
to a USB memory stick.
3. The Montpetit labs do not require an access card to enter and should
be open 24 hours a day. The building itself closes at 11 pm and opens at 6
am.
Sam
an A
lavi-
2016
Linux User Interface
• Linux was designed as a multi-user, networked Operating System (OS)
• Many user interfaces (or “shells”) exist
• Text based and graphical user interfaces (GUIs) are available
3
Linux OS Environment
Kernel
Hardware
Shell Applications Utilities
Sam
an A
lavi-
2016
Text Based User Interfaces
• Most simulation packages run from the text based interface
• We will introduce you to the text based interfaces
• Text based interfaces are often called “command line interfaces”
Linux is difficult to learn at first, but powerful! 4
Sam
an A
lavi-
2016
The Wooki Computer Cluster
•your assignments will be performed on
Wooki
•To learn Linux accounts for all of you have been created on the Wooki
computer cluster.
5
Sam
an A
lavi-
2016
User Accounts on Wooki
Student Name username
Delphine Amellal damellal
Mehran Bagheri mbagheri
Katie Harriman kharriman
Andrew Hollingshead ahollingshead
Ryan MacDonell rmacdonell
Mackenzie Rack mrack
Rebeca Rondon rrondon
Peter Werhun pwerhun
Andrew White awhite
Yijue Xu yijuexu
Initial password: ilovechemistry
(change your password ASAP)
If you are not on this list please let me know right now! 6
Sam
an A
lavi-
2016
How to Log Into Wooki?
From a Windows PC:
• Use the Secure Shell SSH program (free)
• Installed on lab PCs, available for download from course website
1: click on
“Quick Connect”
Do this now
7
2: Type in:
“Host Name” and
“User Name”
Sam
an A
lavi-
2016
8
Changing Your Password and Logging Out
[saman@wooki ~]$ passwd
Changing password for user saman.
Changing password for saman
(current) UNIX password:
- To change your password use the “passwd” command
- To log out use the ‘exit’ or ‘logout’ command
Do this now
(system will ask you for a new password)
Log in and log out of your account to check your new password
Do this now
Sam
an A
lavi-
2016
9
Accessing Wooki from Outside the University
- Wooki is not directly accessible from outside the University. One must
first SSH into a “gateway” or “portal” machine. This is for added
security.
- Using SSH installed on your home computer, use the following to login
information:
Host Name: gateway.science.uottawa.ca
User Name: woolab
Port Number: 22 (default)
The password is: Cluster2010!! (It is case sensitive)
The portal machine is simply another Linux machine. At the command prompt,
type in:
[woolab@gateway ~]$ ssh –X [email protected]
where XXXX is the Wooki username you have been assigned.
Sam
an A
lavi-
2016
10
Linux File System – Absolute Directory Path
/
bin home tmp usr
twoo saman Student
name
project_A project_B
• Top most directory in Linux is the ‘/’ directory or the ‘root’ directory
• Students are first placed in your “HOME” directory i.e., /home/studentname
the full path to this directory is: /home/saman/project_B
•The location of the directory within the file system is called the PATH to
the directory (or file).
share
scratch
Work
folder
Sam
an A
lavi-
2016
11
Linux File System – Relative Directory Path
saman
project_A project_B
• When I log in, this is what I see:
The path to this directory relative to my home directory is: project_B
You need some basic knowledge of the Linux file system to move outside
your home directory.
Sam
an A
lavi-
2016
Absolute vs Relative Directory Paths
/
bin home tmp
twoo saman mary
project_A TEST
The full, absolute path of the TEST directory is: /home/saman/TEST
While in the ‘saman’ directory, one can simply
use the relative path:
cd TEST
‘..’ refers to a directory one level up (wherever you
may be), in this case the parent directory.
To go to the parent directory: cd ..
If you are in the ‘TEST’ directory you can do the following to go directly
into the ‘project_A’ directory
cd ../project_A
To go back to your home directory, no matter what directory you are in
you can use: cd 12
Sam
an A
lavi-
2016
13
Basic File System Commands
Command Meaning
ls Displays a list of files in the
current working directory
cd directory_name change directories
pwd display present working directory
Try making a directory called ‘TEST’ and going into the directory
mkdir directory_name make a new directory
rm filename delete a file
rmdir directory_name delete a directory
file filename display the file type
mv file1 file2 rename or move file1 into file2
cp file1 file2 copy or replace file1 into file2
Sam
an A
lavi-
2016
A directory: /scratch/CHM4390
has been created for the course. Linux course and assignment files will
be placed there.
There is a directory called: Linux_Intro
Copy this file to your HOME directory.
cp /scratch/CHM4390/Linux_Intro/propene.out .
or you can ‘cd’ into the directory
cd /scratch/CHM4390/Linux_Intro
cp propene.out /home/XXXX/
TIP: File names can be auto-completed by pressing the ‘TAB’ key.
The ‘.’ means
the current
directory.
In that directory there is a file called: propene.out
‘XXXX’ is your
username
14
Sam
an A
lavi-
2016
15
/
bin home tmp usr
twoo saman Student A
project_A project_B
share
scratch
Gnuplot Assignment
1 Linux_Intro
scratch
CHM4390
propene.out
Wooki Directory Structure
1) cp /scratch/CHM4390/Linux_Intro/propene.out .
2) cd /scratch/CHM4390/Linux_Intro
cp propene.out /home/XXXX/
Sam
an A
lavi-
2016
File Properties
•Linux files have owners and different read/write privileges
Try the command ‘ls –al’
[saman@wooki ~]$ ls -al
total 28
drwx------ 2 saman woolab 4096 Jan 6 22:09 .
drwxr-xr-x 60 root root 4096 Jan 6 22:28 ..
-rw-r--r-- 1 saman woolab 24 Jan 6 22:09 .bash_logout
-rw-r--r-- 1 saman woolab 176 Jan 6 22:09 stuff.text
drwxr-xr-x 6 saman woolab 4096 Jan 7 15:12 project_A
owner group size creation
date
file name file permission
codes
•Linux file names are all case sensitive
current directory
parent directory
•Linux file names do not need extensions like in Windows i.e. ‘.exe’ but
they are often used.
•Do not use spaces in your file names! 16
Sam
an A
lavi-
2016
Getting Help
man command • lists the ‘man’ or manual pages for the command
example: man ls
info command • lists the ‘info’ pages for the command
• info is more informative than man for beginner
What if you don’t know the command?
apropos keyword •will search a database of relevant commands
• search the internet
•use the ‘apropos’ command
“ls –al” or “ls –a –l” •most Linux commands have options.
• ‘-’ or ‘--‘ designates an command line
option
17
Sam
an A
lavi-
2016
How to View Text Files: Display Commands
Command Meaning
cat file1 lists contents of file1 to screen
more file1 pages through file1 use spacebar to go to next page
head [-number] file1 display the first 10 (or number of) lines of a file
tail [-number] file1 display the last 10 (or number of) lines of a file
•WARNING: Files that are not text files, for example executable
programs, will output gibberish if you try to read their content.
•Press ‘Ctrl-c’ to exit if there is a problem during reading a file
Try viewing the ‘propene.out’ file
18
Sam
an A
lavi-
2016
How to Create and Edit Files?
•We will need to edit ‘input’ files to define the systems for simulations.
•Point-and-click editors like MS Word are not available through the command
line interface.
The ‘Nano’ text editor
•The ‘nano’ editor is an easy to use text editor
•You will need to learn to use ‘nano’ or another editor to complete the
assignments for this course
•Another text editor available on Linux is ‘vi’, but nano is the much
more user friendly.
• It is essential in Linux to learn how to use a text editor.
•nano is sometimes called ‘pico’. nano is actually an open source
clone of the editor ‘pico’.
19
Sam
an A
lavi-
2016
The ‘Nano’ text editor basics
• starting ‘nano’ [saman@wooki ~]$ nano filename
if filename does not exist, it will be created
nano propene.out do this now
Navigation and Moving the Cursor inside a file with nano
•Use the arrow keys, PgDn and PgUp keys to move
Ctrl-a move to beginning of the line
Ctrl-e move to the end of the line
Ctrl-v page forward
Ctrl-y page backward
Other navigation commands in nano
20
Sam
an A
lavi-
2016
•To insert text, simply move the cursor to the point you want to and then start
typing.
Editing Text
backspace delete a single character ‘backward’
Ctrl-r insert a file at cursor position (prompt will appear)
Ctrl-k cut or delete an entire line
Ctrl-u paste
•To select a portion of a line or more than one line for cutting:
1. use the ‘Ctrl-^’ (Ctrl+Shift+6) to mark the beginning of the text
2. Move the cursor to select the text from the ‘marked’ point.
Other editing commands
21
Sam
an A
lavi-
2016
The nano Menu
Nano always has the contextual menu at the bottom of the screen
The ‘^’ or caret symbol means ‘Ctrl-’. Thus, ‘^G’ means press the Ctrl key while
pressing the ‘G’ key. (lowercase ‘g’ works)
There is ‘Help’ menu that you should explore.
In the Help menu the ‘Meta’ symbol (M) means press the ‘Esc’ key then
press the key. E.g. ‘M-g’ means press the Esc key then press the ‘g’ key.
Don’t hold down the Esc key while pressing the ‘g’.
Esc-g or M-g Go to a specific line number
Esc-/ or M-/ Go to the end of the file
22
Sam
an A
lavi-
2016
Saving and Quitting
Ctrl-o save. Nano prompts you for file name
Ctrl-x exit. Nano prompts you to save work if changes were
made since the last save.
Searching for Text
Ctrl-w Search for specific text
23
Sam
an A
lavi-
2016
Copying and Pasting with SecureShell
One can also copy and paste with the SecureShell program. You can do
this any time in Linux, not just when running ̀ nano`.
To copy:
1. Highlight text with mouse.
2. Right-click and select copy from the menu
or
3. Click on “copy” icon on Secure Shell toolbar
Please note the standard Windows keyboard shortcuts Ctrl-c, Ctrl-v are
disabled in Secure Shell because these have special meaning in Linux.
To paste:
1. Right-click and select paste from the menu.
Please note you cannot paste anywhere on the screen in the Secure Shell
window. Pasting is equivalent to typing in with the keyboard. Recall we
are using a text based interface and it doesn’t know about your
‘Windows’ mouse and cursor. 24
Sam
an A
lavi-
2016
Text Editor Exercise
One of the simulation packages we will use is called ‘DL_POLY’.
There are 3 input files that DL_POLY requires
CONTROL, CONFIG, and FIELD
Examples of these files have been placed in /scratch/CHM4390
A. Make a directory called “Problem_1” in your home directory and copy
these files in this directory. Also copy the FIELD_VDW file from
/scratch/CHM4390.
B. The CONTROL input file has some of the set-up parameters for an MD
simulation. The present file has the temperature and pressure of the
simulation set to 250 K and 0.001013 kbar (1 atm), respectively. Make a new
file called CONTROL2 which has the temperature and pressure set to 300 K
and 0.1 kbar.
There are also parts C and D for this exercise, see course website.
(available on the course website, not graded)
25
/scratch/CHM4
390
Sam
an A
lavi-
2016
‘Environment Variables’ in Linux
•An “Environment variable” is an entity that changes its value.
•Software can use environment variables to determine specific
information about the computer or user preferences.
e.g. $HOME = /home/saman
environment variable
changes, depending on the user
•User can change environment variables
•Environment variables are referenced with the ̀ $`
$DEFAULT_PRINTER
$BASIS_SETS
26
Sam
an A
lavi-
2016
‘Environment Variables’ in Linux
How to Display an Environment Variable (the echo command)
[saman@wooki ~]$ echo $HOME
/home/saman
[saman@wooki ~]$ echo $PATH
/usr/local/bin:/usr/bin:/usr/X11R6/bin:/binc
How to Define or Change an Environment Variable (the export command)
[saman@wooki ~]$ export MYNAME=“Saman”
[saman@wooki ~]$ echo $MYNAME
saman
•We will use environment variables sparingly in the course but it is an
important Linux concept.
no ‘$’ sign when
defining
27
Sam
an A
lavi-
2016
The ‘$PATH’ Environment Variable
• $PATH is an important environment variable.
PATH defines a list of directories to search through when looking for a
command to execute
•When you run a Linux command, such as ‘ls’, it actually executes a
program or script from a directory which is accessed by the PATH.
[saman@wooki ~]$ echo $PATH
/usr/local/bin:/usr/bin:/usr/X11R6/bin:/home/saman/bin
•We will not work with the environment variable $PATH much, but the
$PATH is an important concept in Linux for future reference.
28
Sam
an A
lavi-
2016
Other Linux Tricks and Tips
One can scroll through a history of your commands to repeat them more
easily or even search your command history:
• File names can be auto-completed by pressing the ‘TAB’ key.
•To edit the command, use the arrow keys (,) to move the cursor,
the Ctrl-d or ‘Backspace’ to delete a character.
29
•The last 100 commands used can be seen by using the history command
• Commands can be recalled using the up and down arrow keys (, ).
Open another shell without
having to log in. (Try now)
Transfer files between Linux
and Windows. (Try now)
Sam
an A
lavi-
2016
X-windows Server
• graphics application runs on
this machine
• sends graphics information
over internet to the client
X-windows Client
• X-windows client software
interprets graphics information
• displays graphics
X-Windows: The Linux Networked Graphics System
30
• Many computers running Linux (including Wooki) do not have monitors
• One needs to send display (graphical information to a computer with a monitor
• The remote computer you use to log in to Wooki has the ‘monitor’
Sam
an A
lavi-
2016
Setting up your PC to be a X-Windows Client
•MobaXterm is free X-windows client software for Windows XP/Vista/7
• For your Windows laptop or home computer you can
download and install MobaXterm from the website:
http://mobaxterm.mobatek.net/
• First, close any open SSH secure shell windows that are open.
• In Montpetit Hall , launch MobaXterm from the ‘Start’ menu, launch pad.
31
Click here
Sam
an A
lavi-
2016
• Launch a new Secure Shell window with the X11 tunneling turned on.
• Do this by selecting it with the settings window:
32
Sam
an A
lavi-
2016
To test whether X-Windows is working log into Wooki and type xeyes
33
If X-Windows is properly activated, you should see a pair of eyes show up
Sam
an A
lavi-
2016
X-windows can ‘tunnel’ through the UOttawa Firewall (gateway machine)
such that you can use X-windows to Wooki from outside of campus.
X-Windows Thru the Portal from Off-Campus
1. Launch MobaXterm on your home computer.
2. Secure Shell to ‘gateway.science.uottawa.ca’ using the ‘woolab’ account
with the X11 tunneling turned on in the SSH window.
3. When logged onto the portal machine ssh into Wooki using the ‘-X’ option:
[woolab@gateway ~]$ ssh -X [email protected]
Now when you run X-windows programs on Wooki, they should be
redirected through the portal machine to your off-campus computer.
- Graphical application may run very slowly off campus!
34
Allows graphical data to be transferred during the session
Sam
an A
lavi-
2016
gnuplot: A powerful graphics program
gnuplot is a command-line driven plotting program available on Linux.
It can be used to quickly plot simple data, while at the same time being
extremely powerful.
http://www.gnuplot.info.
It can easily perform least squares fitting of data to specific functions that
Excel cannot.
35
Sam
an A
lavi-
2016
Starting Gnuplot
To use gnuplot, make sure that an X-windows session is active
[saman@wooki ~]$ gnuplot
gnuplot>
A gnuplot prompt will appear:
gnuplot> f(x) = 2*x + 5*sin(x)
gnuplot> plot f(x)
gnuplot> set xrange [0:20]
gnuplot> set yrange [0:30]
gnuplot> set xlabel ‘x-axis name’
gnuplot> set ylabel ‘y-axis name’
gnuplot> set grid
gnuplot> replot
Try the following plot settings
36
Sam
an A
lavi-
2016
Plotting Styles
gnuplot> plot f(x) with dots
gnuplot> plot f(x) with points
gnuplot> set pointsize 4
gnuplot> plot f(x) with boxes
gnuplot> plot f(x) with impulses
To Remove the Legend
gnuplot> unset key
To Reset the Plot Settings
gnuplot> reset
37
•Commands can be recalled using the up and down arrow keys (, ).
Sam
an A
lavi-
2016
Plotting Numerical Data from a File
gnuplot> plot ‘filename’ using 1:2
Numerical data stored in columns within a
file can be plotted.
1.0320 6.2074 38.5313
2.0640 8.5465 73.0424
3.0960 6.7056 44.9651
4.1280 4.2160 17.7746
5.1600 5.2054 27.0960
6.1920 10.6029 112.4220
7.2240 17.2849 298.7689
which columns to ‘use’
gnuplot> plot ‘filename’ using 1:2 with linespoints
to change the style
One can plot more than one function
gnuplot> plot ‘filename’ using 1:2 with linespoints, f(x)
separate with commas
38
Sam
an A
lavi-
2016
Fitting Data to a Function
gnuplot> g(x) = a + b*x
Gnuplot performs least squares fitting to both linear and non-linear functions.
gnuplot> fit g(x) ‘/scratch/CHM4390/Gnuplot/linear.dat’ via a,b
gnuplot> plot g(x),‘/scratch/CHM4390/Gnuplot/linear.dat’
Any function can be fit too. Here sometimes, one needs to provide a good
initial guess for the parameters.
gnuplot> b = 5.42 gnuplot> fit g(x) ‘filename’ via a,b
(Note to perform fitting, you need to start gnuplot in a directory that you
have write permission)
39
Sam
an A
lavi-
2016
Output of Fitting Data to a Function
Full output of fitting procedure is given in fit.log
Values of fit
parameters
Sam
an A
lavi-
2016
Gnuplot Exercise
Hand out is part of gnuplot tutorial on course website.
Since the Penguin is the Linux mascot….
41
Sam
an A
lavi-
2016
Gnuplot Exercise
ba pd d /
cm
P / kPa
Least squares fit this distance versus
pressure data:
Find best fit parameters, ‘a’ and ‘b’.
/scratch/CHM4390/Gnuplot/penguin.dat
42
gnuplot> g(x) = a*x**b