First steps on Linux and programming

Similar documents
Perl and R Scripting for Biologists

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Lec 1 add-on: Linux Intro

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

Assignment 1: Communicating with Programs

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda

Chapter 1 - Introduction. September 8, 2016

CMPUT 201: Practical Programming Methodology. Guohui Lin Department of Computing Science University of Alberta September 2018

Linux Command Line Interface. December 27, 2017

Command-line interpreters

CS370 Operating Systems

Introduction to Linux

Files

18-Sep CSCI 2132 Software Development Lecture 6: Links and Inodes. Faculty of Computer Science, Dalhousie University. Lecture 6 p.

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

CSCI 2132 Software Development. Lecture 4: Files and Directories

Introduction to the shell Part II

Shells and Shell Programming

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

Today. Review. Unix as an OS case study Intro to Shell Scripting. What is an Operating System? What are its goals? How do we evaluate it?

5/20/2007. Touring Essential Programs

Introduction To. Barry Grant

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Lecture 1. A. Sahu and S. V. Rao. Indian Institute of Technology Guwahati

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

An Introduction to Unix Power Tools

Getting started with Hugs on Linux

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Chap2: Operating-System Structures

Introduction to Linux

Shells and Shell Programming

Beyond this course. Machine code. Readings: CP:AMA 2.1, 15.4

Introduction to Linux

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Shell Programming Systems Skills in C and Unix

Getting started with Hugs on Linux

Unix System Architecture, File System, and Shell Commands

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Linux Systems Administration Getting Started with Linux

Lecture 7: file I/O, more Unix

Working with Basic Linux. Daniel Balagué

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Introduction to remote command line Linux. Research Computing Team University of Birmingham

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

CSCI2467: Systems Programming Concepts

Introduction. Let s start with the first set of slides

Introduction to Linux

Lecture 9: Potpourri: Call by reference vs call by value Enum / struct / union Advanced Unix

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

Assignment clarifications

Welcome to Linux. Lecture 1.1

Problem Set 1: Unix Commands 1

CHE3935. Lecture 1. Introduction to Linux

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

Linux Essentials. Smith, Roderick W. Table of Contents ISBN-13: Introduction xvii. Chapter 1 Selecting an Operating System 1

CSE Linux VM. For Microsoft Windows. Based on opensuse Leap 42.2

Virtual Machine. Linux flavor : Debian. Everything (except slides) preinstalled for you.

EECS2301. Lab 1 Winter 2016

Working With Unix. Scott A. Handley* September 15, *Adapted from UNIX introduction material created by Dr. Julian Catchen

Recap From Last Time:

Php Scripts If Then Else Linux Bash Shell

1Z Oracle Linux Fundamentals (Oracle Partner Network) Exam Summary Syllabus Questions

BGGN 213 Working with UNIX Barry Grant

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).


Introduction to Linux Organizing Files

The Unix Shell & Shell Scripts

CS 3410 Intro to Unix, shell commands, etc... (slides from Hussam Abu-Libdeh and David Slater)

Short Read Sequencing Analysis Workshop


UNIX. The Very 10 Short Howto for beginners. Soon-Hyung Yook. March 27, Soon-Hyung Yook UNIX March 27, / 29

Bioinformatics? Reads, assembly, annotation, comparative genomics and a bit of phylogeny.

CS : Programming for Non-Majors, Fall 2018 Programming Project #5: Big Statistics Due by 10:20am Wednesday November

Files and Directories

System Administration

Vi & Shell Scripting

Computer Systems and Architecture

Lecture 8: Structs & File I/O

Chapter-3. Introduction to Unix: Fundamental Commands

Introduction in Unix. Linus Torvalds Ken Thompson & Dennis Ritchie

Linux for Beginners. Windows users should download putty or bitvise:

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

A Brief Introduction to Unix

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

Lecture P3: Unix. Overview. Operating Systems. Layers of Abstractions in Unix. Background

PROGRAMMAZIONE I A.A. 2015/2016

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

Lecture 3. Unix. Question? b. The world s best restaurant. c. Being in the top three happiest countries in the world.

EE516: Embedded Software Project 1. Setting Up Environment for Projects

Working with Shell Scripting. Daniel Balagué

Linux Essentials Objectives Topics:

Unix basics exercise MBV-INFX410

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

Linux Shell Script. J. K. Mandal

9.2 Linux Essentials Exam Objectives

ITST Searching, Extracting & Archiving Data

Transcription:

First steps on Linux and programming Adrien Poteaux CRIStAL, Université de Lille Year 2017-2018 This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. http://creativecommons.org/licenses/by-nc-sa/3.0/ adrien.poteaux@univ-lille1.fr Linux? Programming? 1 / 16

Refresher course in Computer Science 6 weeks ; 50 hours in total A lot to do (not in that order): Linux basics / using a shell C language Fortran language Unix system How we ll work: A few lectures, More practical work, 4 projects (50%), One written exam (50%), Documents avalaible at Personal implication: take good uses, practice programmation, read, search on the web... Questions are welcome! http://cristal.univ-lille.fr/~poteaux/teaching.html My email : adrien.poteaux@univ-lille1.fr adrien.poteaux@univ-lille1.fr This lecture 2 / 16

Projects and notations During the lectures, 4 projects will get a mark : Fortran project ; due September 18th, before 9am ; 15% C project 1 (no pointers) ; 10% C project 2 (with pointers) ; 10% A last project (system) ; 15% These deadlines are in bold on the webpage. Remaining of the mark will be on paper: Written exam ; 50% adrien.poteaux@univ-lille1.fr This lecture 3 / 16

How to send your s! One archive by email: adrien.poteaux@univ-lille1.fr, $ tar cvzf yourname-project.tar.gz 1 2... cf man tar It should contain: The requested s (clean code - indentation, comments are welcome - put your names again there), Description of how to compile your s (better : make) Potentially a README (any general comment you want to make... ), No unnecessary (backup s, intermediate compilations s, executables that are generated by your code... ). = I cannot do anything from them! adrien.poteaux@univ-lille1.fr This lecture 4 / 16

Interpreted language vs compiled language Compiled language Interpreted language C, C++, Fortran... Shell, python, perl, php... The compiler transforms source code written in a programming language into binary form (the object code) to create an executable program. Executable is optimised. Produced executable unique to each processor (thus computer). = must be recompiled! The interpreter directly executes a sequence of instructions of the source code. No optimisation. The interpreter is required at each execution. adrien.poteaux@univ-lille1.fr Linux? Programming? 5 / 16

C and Fortran Fortran C Portable code (norm for the language and the librairies) High level language (data structure, functions, separated compilation... ) generic mathematical functions low-level language (bit & adresses manipulation) powerful and efficient languages not really premissive permissive specialised for scientific computing more general (operating system) multidimensional tables and associated functions adrien.poteaux@univ-lille1.fr Linux? Programming? 6 / 16

Compiled language? 1 Conception. Define your algorithm, write in pseudo-code... 2 Coding. Write your source code in a text.c for some C code,.f90 for some Fortran... like this one 3 Compiling your source code from the shell : $ gcc.c, $ gfortran.f90. 4 Execution. $./a.out run the command from the folder where the is! adrien.poteaux@univ-lille1.fr Linux? Programming? 7 / 16

The patriot bug In 1991, a Patriot anti-missile failed to intercept a Scud missile. 28 people were killed. The code worked with time increments of 0.1 s. But 0.1 is not representable in binary. In the 24-bit format used, the number stored was 0.099999904632568359375 The error was 0.0000000953. After 100 hours = 360,000 seconds, time is wrong by 0.34s. In 0.34s, a Scud moves 500m adrien.poteaux@univ-lille1.fr Coding can be messy! 8 / 16

A real story (appeared at CERN) Using a IA32/x87 FPU (provides a 80 bit double extended format): Use the (robust and tested) standard sort function of the STL C++ library to sort objects by their radius: according to x x +y y. Sometimes (rarely) segfault, infinite loop... Why? Because the sort algorithm works under the following naive assumption: if A B, then, later, A B x x +y y inlined and compiled differently at two points of the program, computation on 64 or 80 bits, depending on register allocation enough to break the assumption (horribly rarely). No programming mistake! (thus very difficult to fix) adrien.poteaux@univ-lille1.fr Coding can be messy! 9 / 16

Another example: equality with floating point numbers What do you believe the following C program will print? (i.e. the execution of its compilation: $ gcc.c ;./a.out) # include <stdio.h> int main() { int i; float ref,index; ref = 169.0 / 170.0; for ( i = 0; i < 250; i ++) { index = i ; if (ref==(index/(index+1.0))) break; } printf ("i = %d\n", i ) ; return 0; } adrien.poteaux@univ-lille1.fr Coding can be messy! 10 / 16

Another example: equality with floating point numbers What do you believe the following C program will print? (i.e. the execution of its compilation: $ gcc.c ;./a.out) # include <stdio.h> int main() { int i; float ref,index; ref = 169.0 / 170.0; for ( i = 0; i < 250; i ++) { index = i ; if (ref==(index/(index+1.0))) break; } printf ("i = %d\n", i ) ; return 0; } Answer: i = 250 adrien.poteaux@univ-lille1.fr Coding can be messy! 10 / 16

Shell? interface between the user and the OS used to run commands / filters stdout, 1: standard output (default: screen) stdin, 0: standard input (default: keyboard) filter/command other s stderr, 2: error output (default: screen) One filter = one identifier (ls) + options (-al) + parameters (/bin) Each process returns a retour code (one byte echo $?). adrien.poteaux@univ-lille1.fr Linux? Programming? 11 / 16

Why using it? Some time to learn how to use it properly but... $ ls *.jpg wc -l will count the number jpeg pictures in the current directory (assuming they are correctly named). $ for i in *.JPG ; do mv $i `basename $i.jpg`.jpg ; done change the extension JPG by jpg for any concerned in the current directory. Way faster, and sometimes you have no choice! adrien.poteaux@univ-lille1.fr Linux? Programming? 12 / 16

Running commands The main idea : (options are parameters!) $ cmd [options] parameters Example, to start Firefox : $ firefox A parameter can be a bloc: $ command arg1 'arg 2 toto' "arg 3'" Running a command in background: $ emacs & Forgot to do so? C-z then $ bg A lot more! Cf chapter 1 of the lecture notes. Only one way to learn : PRACTICE! adrien.poteaux@univ-lille1.fr Linux? Programming? 13 / 16

Filesystem root home bin directory tmp ls cd rm poteaux toto.txt CS slides-shell.tex adrien.poteaux@univ-lille1.fr Filesystem 14 / 16

Absolute path (from the root) root home bin directory tmp ls cd rm poteaux toto.txt $ emacs /home/poteaux/cs/slides-shell.tex CS slides-shell.tex adrien.poteaux@univ-lille1.fr Filesystem 14 / 16

Absolute path (from the root) root home bin directory tmp ls cd rm poteaux toto.txt $ emacs $HOME/CS/slides-shell.tex CS slides-shell.tex adrien.poteaux@univ-lille1.fr Filesystem 14 / 16

Absolute path (from the root) root home bin directory tmp ls cd rm poteaux toto.txt $ emacs ~/CS/slides-shell.tex CS slides-shell.tex adrien.poteaux@univ-lille1.fr Filesystem 14 / 16

Relative path (from the current directory) root home bin directory tmp ls cd rm poteaux toto.txt $ cd $ emacs CS/slides-shell.tex CS slides-shell.tex adrien.poteaux@univ-lille1.fr Filesystem 14 / 16

Relative path (from the current directory) root home bin directory tmp ls cd rm poteaux toto.txt CS $ cd $ emacs CS/slides-shell.tex & $ cd CS ;$ emacs slides-shell.tex slides-shell.tex adrien.poteaux@univ-lille1.fr Filesystem 14 / 16

Relative path (from the current directory) root home bin directory tmp ls cd rm poteaux toto.txt $ cd /directory $ /bin/rm CS slides-shell.tex adrien.poteaux@univ-lille1.fr Filesystem 14 / 16

root home bin directory tmp ls cd rm poteaux toto.txt CS $ cd /directory $ rm (try echo $PATH) slides-shell.tex adrien.poteaux@univ-lille1.fr Filesystem 14 / 16

Redirections root home bin directory tmp ls cd rm poteaux toto.txt $ cd ; ls CS > /tmp/toto.txt CS slides-shell.tex adrien.poteaux@univ-lille1.fr Filesystem 14 / 16

Redirections root home bin directory tmp ls cd rm poteaux toto.txt CS $ cd ; ls CS > /tmp/toto.txt $ ls CS >> /tmp/toto.txt slides-shell.tex adrien.poteaux@univ-lille1.fr Filesystem 14 / 16

A graph organisation root home bin directory tmp.. ls cd rm poteaux toto.txt. link $ cd ; emacs../poteaux/./link CS similar to $ emacs /directory/ slides-shell.tex adrien.poteaux@univ-lille1.fr Filesystem 14 / 16

Use the good tools! The key command: man. Uses the less viewer: h will display the available commands, q will quit the viewer, / followed by an expression will search the next apparition of this expression in the document, move to the first results, and highlight the others, n moves to the next apparition of the searched expression, N moves to the previous apparition of the searched expression, Use a programming text editor (emacs, vi). First contact is frightening but worths it! Print the refcard! Learn some shortcuts! (try not to use the mouse) Read more (links on the webpage)! Practice! An Introduction to the Linux Command Shell For Beginners, Unix Programming Tools (sections 4 and 5 at the moment). adrien.poteaux@univ-lille1.fr Miscellaneous 15 / 16

Script: short definition File containing shell commands. Interpret the : $. foo (in the current shell), $ sh foo (in another shell),... Run the directly: Need to be executable (chmod) Magic number: #!/bin/sh interpreted in a another shell Remark /bin/sh is just a link to the shell interpreter you are using. It can be for instance bash, dash or csh. You can see which version you are using via the command $ ls -l /bin/sh adrien.poteaux@univ-lille1.fr Miscellaneous 16 / 16