Ub Phy410 Compphys Linuxoverview 3
Ub Phy410 Compphys Linuxoverview 3
Computational Physics 1
Salvatore Rappoccio
1
Technical Lectures
• We will have several technical lectures to get you up to
speed with programming and technical skills
– Using UNIX/LINUX command line
– Compiling, version control
– Data representations, flow of control, object oriented
programming, simple algorithms
Executing code
• The official environment for the class is a container:
– Docker image for class software (Ubuntu based):
• https://hub.docker.com/r/ubsuny/compphys
Executing code
• Some people that have tablet two-in-one “laptops” will
have trouble with containers
– This is because the tablet is basically a large phone with
a keyboard, and we need a “real” computer capable of
running virtual machines
– For those at UB: If you do not have a powerful enough
laptop, you can use the SENS cluster.
– For those elsewhere: singularity is installed at the LPC
so if you have an account there, instructions can be
provided by the LPC staff to run the container.
Containers
Containers
• Why bother?
– So you don’t have to spend time configuring software. It
just works.
• Instructions:
– Get docker : https://docs.docker.com/install/
• (shortcuts: https://download.docker.com)
– Follow installation instructions (OS dependent)
– Once it is running, open your “Terminal” app in your
laptop / host machine, and execute these:
git clone https://github.com/ubsuny/CompPhys.git
chmod a+w CompPhys
cd CompPhys
./runDocker.sh ubsuny/compphys:latest
6
Containers
• You will get a command line just like a linux computer
(running Ubuntu)
% ./runDocker.sh srappoccio/compphys:latest
192.168.1.231 being added to access control list
compphys@55d39ad05e02:/Users/rappoccio/dockers/CompPhys$
UNIX/LINUX
• Operating systems (like Windows or Mac OS)
Linux Shells
• We will be using an interface to Linux called a “shell”
• It is a command-line interpreter : you type, it executes
• Two major options are “bash” (as in, smash) and “csh” (like
“sea shell”, modern version is “tcsh”, “tea sea shell”)
• For the most part, few differences with respect to this
class, you can use either one.
Jupyter
• We will (judiciously) use Jupyter notebooks
• Also can be installed on your own machines if you want
• Nice little package for code and documentation at once
– Note: This is usually not for “industrial strength” software,
but for prototyping and communication!
10
Jupyter
• We will (judiciously) use Jupyter notebooks
• Also can be installed on your own machines if you want
• Nice little package for code and documentation at once
– Note: This is usually not for “industrial strength” software,
but for prototyping and communication!
• To run: jupyter notebook --ip 0.0.0.0 --no-browser
Jupyter
• Now you’re running jupyter locally:
12
Jupyter
13
Jupyter
Type python
Shift+Enter: It executes
Copy-and-paste-able:
import matplotlib.pyplot as plt
import array
x = array.array('f', [1,2,3])
y = array.array('f', [1,4,9])
plt.plot(x,y)
14
plt.show
Jupyter
15
Jupyter
16
Jupyter
• But wait, it gets better! If you want, you can use the Jupyter
terminal directly instead of the linux shell.
Gives you:
17
Jupyter
Click to “JupyterExamples”,
18
Jupyter
To run:
Kernel:
Restart and Run All
Boom! Jupyter-ed.
19
Linux Command Line
• Basics : Listing directory contents : “ls”, like “list”
$ ls
$
21
22
• Move : “mv” :
$ ls
stuff2.txt stuffagain.txt stuff.txt
$ mv stuff1.txt stuff2.txt
$ cat stuff2.txt
Who am I?
– File “stuff2.txt” is there, but “stuff1.txt” is gone
– Also known as “renaming”! 23
– Example:
$ cp stuff.txt stuff_backup_27jan2017.txt
– OR! Use version control (more on that later)
24
– wildcards!
25
Hands on!
• Open terminal, go to “CompPhys/LinuxOverview”
• Look at “commandline1.sh” file:
% more commandline1.sh
echo "Always look on the bright side of life" > bright.txt
echo "If life is jolly rotten, there's something you've
forgotten" > forgotten.txt
cat bright.txt forgotten.txt > song.txt
cat song.txt=
• Execute:
% bash commandline1.sh
• Output:
Always look on the bright side of life
If life is jolly rotten, there's something you've forgotten
• Type “ls”:
bright.txt commandline1.sh forgotten.txt song.txt
$ ls s*.txt
song.txt stuffagain.txt stuff_backup_27jan2017.txt stuff.txt
27
28
29
Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file
-b, --escape print octal escapes for nongraphic characters
--block-size=SIZE use SIZE-byte blocks. See SIZE format below
• Common options
– “-l” : long listing
– “-a” : list all
– “-t” : list by time
– “-r” reverse
30
Linux Security
Filename
31
Linux Security
Time/date Filename
of last mod.
32
Linux Security
33
Linux Security
34
Linux Security
• Levels of security :
– All : everyone
– Group : a group of users
– Owner : the owner of the file
• Access levels :
– Read : Can read from file
– Write : Can write to file
– Execute : Can execute if it is a program
Linux Security
• You can change the permissions, the owners, or the
groups of files:
36
Linux Directories
• To make directories, use “mkdir”:
$ mkdir testdir
$ ls
bright.txt commandline1.sh forgotten.txt song.txt testdir
• You can move files from one directory to another with “mv”
just like before:
$ mv song.txt testdir/
37
Linux Directories
• The directory you are “in” is called the “current directory”
• To change your current directory, use “cd”:
$ cd testdir
/nsm/home/srrappoc/testdir
$ ls
song.txt
Editors
• AKA : why is it so f*ing hard to type stuff in Linux?
– It isn’t, you’re just not thinking about it right :)
– If you’re sitting at the same terminal you’re executing
commands on, your server is the same as your client
– If you’re using ssh, you are trying to send a ton of
graphical information over the net to type
39
Editors
• Linux comes with the “X11” graphics package : that’s how
everything works
– This is also the basis for Mac OS’s GUI
40
Editors
http://cube-drone.com/comics/c/holy-war
41
Editors
42
Editors
• I am personally firmly in the “Emacs” zone of the world
• If you are a vi or ed user, you can leave now
– Kidding!!! *coughsortofcough*
• I can teach you the basics of emacs, and you should learn
the rest on your own. You’re scientists, that’s how it goes.
It’s like learning to walk, or ride a bike, or hazing or
something.
43
Editors
• emacs :
– X mode : emacs filename.txt &
• Edit away as you want.
– Terminal mode : emacs -nw filename.txt
• “-nw” is “no window”
– Tutorial : https://www.gnu.org/software/emacs/tour/
• vi / vim:
– vi filename.txt
– I suck at vi, so just go here:
• https://scotch.io/tutorials/getting-started-with-vim-an-interactive-
guide
44
Editors
• If you’re terrified of learning how to use these, just use
“nano”. The interface is straightforward, but has extremely
few features.
45
Editing: Docker
• There is no emacs in our docker image
• There is no vi in our docker image
• There is no editor at all
• WTH Sal?!!?
46
Editing: Docker
• Open the files directly in your host operating system (i.e.
the normal way you edit stuff on your computer)
compphys@d4fa2e3932fb:/Users/rappoccio/dockers/CompPhys$
The file is here on your host operating system, just edit in a different terminal!
47