© Janice Regan, CMPT 102, Sept. 2006 0 CMPT 102 Introduction to Scientific Computer Programming Preparation for working in the CSIL Basic LINUX operations.

Slides:



Advertisements
Similar presentations
Linux commands exercise 1. What do you need, if you try to these at home? You need to download and install Ubuntu Linux from the Internet – DVD is need.
Advertisements

CMPT 471 Networking II Linux Primer 1© Janice Regan, 2013.
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Working with Files How to create, view, copy, rename and print files.
Lab6 CPCS361 I.Mona Alshehri. Working with Files and Directories Creating files Create a file with the cat command type the command cat > name_of_file.
Cosc 4750 Getting Started in UNIX Don’t be afraid of the prompt, in linux it can be your best friend. In some cases, the only way to do certain things.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
Linux+ Guide to Linux Certification, Second Edition
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Building User Libraries.
UNIX Chapter 00 A “ Quick Start ” into UNIX Operating System Mr. Mohammad Smirat.
9-2 How do you copy/move/rename/remove files? How do you create a directory ? What is redirection and piping? Readings: See CCSO’s Unix pages andCCSO’s.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Linux Installation and Administration Lesson 2 Tutor: George Papamarkos.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID COSC 513 Operating System.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
CHAPTER 1 UNIX FOR NONPROGRAMMERS By U ğ ur Halıcı.
Working with Files Chapter 5. Display a Calendar Display a calendar for a specific month – cal Display a calendar for a specific year – cal 2000.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Introduction to Shell Script Programming
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
BIF703 stdin, stdout, stderr Redirection. stdin, stdout, stderr Recall the Unix philosophy “do one thing well”. Unix has over one thousand commands (utilities)
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
AN INTRO TO UNIX/LINUX COMMANDS BY: JIAYANG WANG.
Linux+ Guide to Linux Certification, Third Edition
1 N305 C Programming. 2 Objectives for the Lab ä Learn problem solving strategies ä Achieve intermediate knowledge of C Programming Language ä Gain experience.
CS240 Computer Science II Introduction the Unix File System and File Related Utilities Based on “UNIX for Programmers and Users” by G.Class and K. Ables.
1 The EDIT Program The Edit program is a full screen text editor that allows you to: Create text files Create text files Edit an existing text files Edit.
Week 3 Exploring Linux Filesystems. Objectives  Understand and navigate the Linux directory structure using relative and absolute pathnames  Describe.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
1 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Some content in this lecture added.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
Introduction to UNIX Geraint Vaughan. What is UNIX? Command-line operating system (not point- and click) Designed for ‘experts’ Lots of different variants.
Welcome to CS323 Operating System lab 1 TA: Nouf Al-Harbi NoufNaief.net.
Basic Unix Commands CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: whereis, which, whoami, finger, passwd, cal, date Working with Files: cat, more, less.
1May 16, 2005 Week 2 Lab Agenda Command Line FTP Commands Review More UNIX commands to learn File name expansion - * Introduction of vi.
Introduction to Programming Using C An Introduction to Operating Systems.
The Genome Analysis Centre Building Excellence in Genomics and Computational Bioscience.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
THE UNIX SYSTEM Jan Recitation 2 Introduction to Networking.
AN INTRO TO UNIX/LINUX COMMANDS BY: JIAYANG WANG.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Linux A practical introduction. 1)Background and Getting Started Linux is an operating system with multiple providers Red Hat/CentOS (our version) Ubuntu.
1 Week # 4 Introduction to PDM PDM is a workbench environment that lets programmers and system operators navigate the three levels of the AS/400’s object-based.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
CMSC 104, Version 8/061L03OperatingSystems.ppt Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux.
Learning Unix/Linux Based on slides from: Eric Bishop.
Linux CSE 1222 CSE1222: Lecture 1BThe Ohio State University1.
Assignprelim.1 Assignment Preliminaries © 2012 B. Wilkinson/Clayton Ferner. Modification date: Jan 16a, 2014.
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Prepared by: Eng. Maryam Adel Abdel-Hady
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Some Linux Commands.
Lab 2: Terminal Basics.
Presentation transcript:

© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Preparation for working in the CSIL Basic LINUX operations Compiling, Linking, and Running Your Program

© Janice Regan, CMPT 102, Sept Using Basic LINUX Commands  To develop your programs you must first learn how to accomplish simple tasks within the LINUX operating system  Creating/Deleting and Editing files  Moving from directory to directory, and finding files  Organizing files, making your own directories  Compiling your program files  Interpreting and correcting syntax and semantic errors  Linking your programs  Running your programs  Debugging (finding and correcting all types of errors in your programs)

© Janice Regan, CMPT 102, Sept Some basic commands  LINIX IS CASE SENSITIVE  Rectangle is NOT the same as RECTANGLE  passwd  Executed from your command line  Will ask you to input your old password and your new passwd twice  You can only change your own passwd  man commandname or info commandname  Tell me how to use the command, commandname  man –k string  Give me a l ist of commands whose descriptions include string  whoami  Tell me my username

© Janice Regan, CMPT 102, Sept Directory structure  cd change directory  In myhome  cd Dir2 (goes to Dir2, the child directory of myhome)  cd Dir3/Dir5 (goes to Dir5 )  In Dir5  cd.. (goes to Dir3, the parent directory of Dir5)  cd../.. Or cd (goes to myhome)  cd../Dir6 (goes to Dir6)  Anywhere cd will take you to myhome (your home directory)  When you log in you will find yourself in your home directory Dir1 Dir5Dir6Dir7 myhome Dir2Dir3Dir4

© Janice Regan, CMPT 102, Sept Using the directory structure  When you log in to begin an assignment, you will find yourself in your home directory  If your computer id is jones, then the name of your home directory will be jones (/home/jones)  You should make yourself a directory for the assignment, say ass1  To make a directory ass1 in directory jones cd mkdir ass1  Move into your new directory before starting your assignment cd ass1

© Janice Regan, CMPT 102, Sept Beginning to write your program  You are now in a subdirectory that you created for your assignment  Next you need to create the file into which you will put your program  To created the file use a text editor. If the text editor is kate then  kate prog1.c Will create a file called prog1.c, in directory ass1 into which you will put your C program prog1. If the file prog1.c already exists it will be opened and ready to be modified.

© Janice Regan, CMPT 102, Sept Moving, Renaming or Deleting Files  mv move file used to move or rename a file  mv a b file previously named a is now named b  mv a../a file a is moved from the present directory to the parent directory of the present directory  mv a d/a file a is moved from the present directory to the child directory a of the child directory d  rm remove fileused to delete a file  rm a1 deletes a file, a1, from the current directory  rm../a1 removes a file, a1, from the parent of the present directory  rm d/a1 removes a file, a1, from the child directory a of the child directory d

© Janice Regan, CMPT 102, Sept Where am I? What is here? Is it in this file?  pwdWhat is the name of the directory I am in  ls give me a list of all the files in this directory  ls –al give me a list with more information about each file  grep pattern filepaths  Find all occurrences of pattern in requested files

© Janice Regan, CMPT 102, Sept Copying, viewing, and combining Files  more filename or less filename  Displays contents of file filename one page (screen) at a time  cp filename1 filename2  Make a copy of filename1 with name filename2  cat filename1 filename2 filename3  Will print the contents of each file in sequence Contents of filename1 Contents of filename2 Contents of filename3

© Janice Regan, CMPT 102, Sept Wildcards  Wildcards are used to represent multiple possibilities  * matches any number of characters  ? Matches a single character  Examples  ls a? List all files in the current directory beginning with a and having a name of length 2 characters.  grep mystring */*file Find all occurences of the string “mystring” in all files whose names end with the string “file”. The files ending with string “file” must be in a subdirectory of the present directory  rm [a-c]* Remove all files with filenames beginning with a b or c from the current directory

© Janice Regan, CMPT 102, Sept Redirection  Redirect input and/or output  > filename redirect standard output from screen to file. cat file1 file2 file3 > f4 A new file f4 is opened and the contents of file1, file2 and file 3 are successively added to the file f4. If f4 exists it will be overwritten.  < filename take input from file filename a.out < datafile (a.out is the default output file for a compiled executable)

© Janice Regan, CMPT 102, Sept Redirection and Piping  Redirection  >> filename redirect standard output from screen to file. Appends output to an existing file cat file1 file2 file3 >> f4 The contents of file1 then file2 then file3 will be successively appended to the current contents of f4  Piping allows you to send the output of one process to become the input of another process without using io to store it in an intermediate file  ls a* | more List the files in the current directory whose names start with a, one page at a time

© Janice Regan, CMPT 102, Sept Creating, Editing and Deleting Program Files  For program files and data files you must use a text editor not a word processor  In Windows Word is a word processor. The file it saves includes information in addition to the text that appears on your page. The information is stored in a file with a special format that is readable only by the word processor application.  In windows Notepad is a text editor it saves only the text you type in. The text is stored as simple characters and is readable by many applications including compilers  In Linux the suggested text editor is called kate. If you are already familiar with LINUX you may use your favorite text editor

© Janice Regan, CMPT 102, Sept Writing your program  Log in to a Linux machine (or a Cygwin window if you are working at home)  The red hat on the bar at the bottom of the screen is the icon for your start menu.  Select system tools from your start menu  Select terminal from the system tools menu  A terminal window like the one below will appear  In the terminal window type kate, followed by enter  A kate text editor window should open for you.

© Janice Regan, CMPT 102, Sept Entering your program into a file  Either  Enter the command kate followed by enter, to open kate  Type your program into the blank kate text editor window  Save your program to a file with a name ending in.c  Or  Open you program file with the command kate programname.c  Select Open from the file menu  Browse to find the existing file you wish to edit  Select the file to edit, then make desired changes to the contents of the file Each time you make changes to your program save those changes by selecting save in the file menu in kate. After saving reload by selecting reload from the kate file menu

© Janice Regan, CMPT 102, Sept Next step, compile the program  Compile your program  Make sure your most recent changes have been saved, and that the saved file has been reloaded into kate.  Press the terminal icon at the bottom of the kate window. This will produce a split screen, the upper window will contain you code in the kate editor, the lower half is a terminal window in which you can type in the commands discussed below.  To compile the program in the text file filename.c execute the following command by typing it into the kate terminal window (remember to type the enter key after the end of the command) gcc –Wall –c –o programname.o programname.c

© Janice Regan, CMPT 102, Sept Basics of compiling with gcc  gcc –Wall –c –o programname.o programname.c  gcc is the name of the c compiler application we are using (GNU C Compiler or GCC). There are many options available when using this compiler, we will cover only a few of these options in this course, You can see explanations of these and other options at any time by typing man gcc.  -Wall is an option that provides more extensive compiler messages warning you of potential problems in your code. These extra warning messages will help you find the problems in your code.  -c and option that tells the c compiler to compile the input text file only, the linker will not be executed.

© Janice Regan, CMPT 102, Sept Basics of compiling with gcc  gcc –Wall –c –o programname.o programname.c  -o filename.o specifies that the name of the object file which will contain your compiled code. In the case of the example above this name would be expansion.o. Regardless of the name you use for your object file it should end in.o to tell the compiler it is an object file resulting from compiling a c text file.  filename.c The test file containing the C code you wish to compile. The name of this file must end with.c. Ending the file with.c tells the compiler that the text file contains C code, rather than objective C, C++, or other flavors of C code that this compiler also supports.

© Janice Regan, CMPT 102, Sept After trying to compile …  When you compile your code using a variant of the command above (filenames will change) you will observe one of two outcomes  You will see a prompt just like the one at which you typed in the command above. This means that your C code has been successfully compiled, and an object file containing the compiled code has been created

© Janice Regan, CMPT 102, Sept After trying to compile …  You will see a list of error messages that tell you there are still syntax and semantic errors within your C code. In this case no object file is created, (Be careful, if you have an object file from a previous version of your code, linking the object file after a failed compile will mean you are recreating the previous version not the present version with your most recent changes). Your next task is to correct those compile time errors and recompile the text file. Remember to save and reload your file after each group of changes you make before you recompile.

© Janice Regan, CMPT 102, Sept Linking your program  When you can compile your code successfully try linking your code  To link the object file expansion.o execute the following command by typing it into the kate terminal window (remember to type the enter key after the end of the command)  gcc programname.o -lm -o programname

© Janice Regan, CMPT 102, Sept Linking your program  gcc programname.o -lm -o programname  expansion.o specifies that the name of the object file which contains your compiled code. In the case of the example above this name would be expansion.o. Regardless of the name you use for your object file it should end in.o to tell the compiler it is an object file resulting from compiling a c text file.  -l specifies that a library should be linked with your input object code to produce your output executable code. In the example above –lm indicates that the standard math library should be linked with you own object code. You will need the standard math library is you use any functions like sin, cos, exp (exponential) etc.

© Janice Regan, CMPT 102, Sept Linking your program  gcc programname.o -lm -o programname  -o expansion specifies that the name of the executable file which will contain the compiled and linked code. In the case of the exampleabove this name would be expansion. It is not necessary to give your executable file any particular extension (like.exe) to identify them

© Janice Regan, CMPT 102, Sept  You can also compile and link your code with a single command (shown below). In this case no object code will be created, you will create an executable file directly from your C text file.  gcc -Wall -lm -o programname programname.c

© Janice Regan, CMPT 102, Sept Running and debugging your code  To run your executable code from the terminal window execute the command below by typing it and then pressing the enter key./programfile  One of three outcomes will happen when you run your program  Your program may work correctly and print the expected results OR  Your program may terminate with and error OR  You program may complete and produce an incorrect answer  In the second two cases you will need to correct your logic errors. After correcting your errors you will need to save your changes, reload the file into kate, recompile and relink before you can retest your new executable file