Temple University Computer Science Programming Under the Linux Operating System January 2017

Similar documents
LAB #5 Intro to Linux and Python on ENGR

Lab 1 Introduction to UNIX and C

Intermediate Programming, Spring Misha Kazhdan

CSCI 161: Introduction to Programming I Lab 1a: Programming Environment: Linux and Eclipse

Once you have installed MobaXterm, open MobaXterm. Go to Sessions -> New Session, and click on the SSH icon.

CpSc 1111 Lab 1 Introduction to Unix Systems, Editors, and C

CS CS Tutorial 2 2 Winter 2018

CSC111 Computer Science II

Parallel Programming Pre-Assignment. Setting up the Software Environment

CS 2400 Laboratory Assignment #1: Exercises in Compilation and the UNIX Programming Environment (100 pts.)

Introduction to Linux Spring 2014, Section 02, Lecture 3 Jason Tang

C++ Programming on Linux

Helpful Tips for Labs. CS140, Spring 2015

15-122: Principles of Imperative Computation

Editing, Compiling, Executing and Submitting Programs

Lab 1: Accessing the Linux Operating System Spring 2009

User Guide Version 2.0

Author A.Kishore/Sachin WinSCP

You can use the WinSCP program to load or copy (FTP) files from your computer onto the Codd server.

EKT332 COMPUTER NETWORK

Saint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry

213/513/613 Linux/Git Bootcamp. Cyrus, Eugene, Minji, Niko

Short Read Sequencing Analysis Workshop

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Table Of Contents. 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands

CS Fundamentals of Programming II Fall Very Basic UNIX

Parallel Programming Pre-Assignment. Setting up the Software Environment

CMSC 201 Spring 2017 Lab 01 Hello World

UoW HPC Quick Start. Information Technology Services University of Wollongong. ( Last updated on October 10, 2011)

Getting Started With UNIX Lab Exercises

CS 261 Recitation 1 Compiling C on UNIX

Programming and Data Structure Laboratory (CS13002)

Using the Zoo Workstations

CMSC 201 Spring 2018 Lab 01 Hello World

Linux/Cygwin Practice Computer Architecture

CS 246 Winter Tutorial 1

Lab 3a Using the vi editor

WinSCP. Author A.Kishore/Sachin

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

Getting Started with UNIX

New User Tutorial. OSU High Performance Computing Center

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

Lab 1 Introduction to UNIX and C

Compiling C/C++ programs

CISC 220 fall 2011, set 1: Linux basics

Linux Tutorial #1. Introduction. Login to a remote Linux machine. Using vim to create and edit C++ programs

Introduction to Algorithms and Programming I Lab. Exercises #1 Solution

You should see something like this, called the prompt :

Practical Session 0 Introduction to Linux

Introduction. SSH Secure Shell Client 1

One of the hardest things you have to do is to keep track of three kinds of commands when writing and running computer programs. Those commands are:

Introduction to the Linux Command Line

STA 303 / 1002 Using SAS on CQUEST

Introduction to Linux Environment. Yun-Wen Chen

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

CS1110 Lab 1 (Jan 27-28, 2015)

Introduction to Linux Workshop 2. The George Washington University SEAS Computing Facility

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

Linux hep.wisc.edu

1 Getting Started with Linux.

Lab 1: Introduction to C, ASCII ART & the Linux Command Line

Introduction to Unix - Lab Exercise 0

CSC UNIX System, Spring 2015

Helsinki 19 Jan Practical course in genome bioinformatics DAY 0

Exercise 1: Basic Tools

BIF713. Operating Systems & Project Management. Instructor: Murray Saul Webpage: murraysaul.wordpress.

CSE 391 Editing and Moving Files

An Introductory Tutorial on UNIX

Setting up my Dev Environment ECS 030

The Unix Shell & Shell Scripts

The Command Shell. Fundamentals of Computer Science

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

Introduction in Unix. Linus Torvalds Ken Thompson & Dennis Ritchie

Problem Set 1 Due: 11:59pm Wednesday, February 7

Carnegie Mellon. Linux Boot Camp. Jack, Matthew, Nishad, Stanley 6 Sep 2016

COP4530 Data Structures, Algorithms and Generic Programming Recitation 3 Date: January 20 & 22, 2009

Using WestGrid from the desktop Oct on Access Grid

CS Operating Systems, Fall 2018 Project #0 Description

CS1600 Lab Assignment 1 Spring 2016 Due: Feb. 2, 2016 POINTS: 10

Part I. Introduction to Linux

AMS 200: Working on Linux/Unix Machines

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions

CSC 112 Lab 1: Introduction to Unix and C++ Fall 2009

WELCOME TO PROGRAMMING

sftp - secure file transfer program - how to transfer files to and from nrs-labs

Mills HPC Tutorial Series. Linux Basics I

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Unix. Examples: OS X and Ubuntu

Lab 2 Building on Linux

Part I. UNIX Workshop Series: Quick-Start

Adafruit's Raspberry Pi Lesson 6. Using SSH

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

Intro to Linux. this will open up a new terminal window for you is super convenient on the computers in the lab

CS 460 Linux Tutorial

Unix basics exercise MBV-INFX410

Introduction. Overview of 201 Lab and Linux Tutorials. Stef Nychka. September 10, Department of Computing Science University of Alberta

Quick Start Guide. by Burak Himmetoglu. Supercomputing Consultant. Enterprise Technology Services & Center for Scientific Computing

CS251 Programming Languages Handout # 3 Wellesley College 30 January Linux, X, and Emacs

Introduction: What is Unix?

CHE3935. Lecture 1. Introduction to Linux

Transcription:

Temple University Computer Science Programming Under the Linux Operating System January 2017 Here are the Linux commands you need to know to get started with Lab 1, and all subsequent labs as well. These commands should work on any Linux system. Note that whenever you see a in my examples below, it means you should press the SPACE bar. The represents a mandatory space. This document details the following steps in logging in, writing a program, compiling it and running it, as well as submitting it for grading. 1. Login to the Astro Linux system. 2. Create a new directory using mkdir. 3. Change into that directory using cd. 4. Confirm you're in the right directory using pwd. 5. Create or Edit the C source code using nano or vi. 6. Save your source code, confirm it's saved, and continue editing. 7. Compile your source code with the cc command. 8. Run your compiled program with the./a.out command. 9. Save a copy of your source code for backup using sendmail or scp. 10. Script the run of your program to capture input and output using script. 11. Email in you submission for grading to labwork@temple.edu. You should take your time doing this process, making sure to follow the steps carefully. In time, given repetition and some effort, you will memorize these steps and it will be easier than it looks. Page 1 of 11

-- STEP 1 -- Login to the Linux system using the SSH client on your machine. For our C programming class, we are using the machine with a name of astro.temple.edu The lab instructor will confirm this and can assist you with the steps involved for the particular classroom you're working in for the semester. Once you connect to the Linux machine, the default prompt under Linux will look like the following: [astro] ~ % That is the Linux prompt. Linux commands can be typed whenever you see the Linux prompt. The ~ in the linux prompt means you are in your home directory. If you are in a differnt directory, the ~ will be replaced with the name of the directory you are in. For example, if you re in the lab1 directory to work on the first lab, the Linux prompt will appear as follows: [astro] ~/lab1 % The arrow keys and mouse generally do not function as you expect when you're working at the Linux prompt. The arrow keys should work in the nano editor, but the mouse probably won't. Page 2 of 11

If you're not in the lab classroom and want to work remotely, then one of the following methods can be used to access the computing resource for this class: Apple Macintosh or Linux Desktop If you're working from a Mac or a Linux machine, you already have an ssh client installed. To use it, open up a new terminal (Apple) or xterm (Linux). Once at the prompt on the desktop, you can use the commadn ssh tuc49583@astro.temple.edu replacing the tuc49583 in the above command with your Temple AccessNet id. Windows 7 and 8 Under Windows, most people use either Putty or Secure Shell Client to connect to our Linux server. If you don't already have one of these, Temple's Computer Services department makes Secure Shell Client available from their web site for free. The URL is https://download.temple.edu After you go to this site, login, and scroll down the list of software looking for a Software Title of 'ssh'. Download and install it the software. Once installed, you will see it on your app screen as follows: You can then click it to run it on your desktop. When prompted, enter in the Host Name and User Name as shown below. Page 3 of 11

Windows 7 and 8 (continued) You may get a prompt about saving the host identification key. Click on the Yes button. Generally, this only has to be done once. Then enter your AccessNet password and you should be connected to the server and see the Linux prompt. Page 4 of 11

-- STEP 2 -- For each lab assignment, create a separate directory. This helps us stay organized and keep our source code for different projects separate. The first Linux command we will learn is the one for creating a new directory. Directories are like folders, holding the files and other directories you need to accomplish a particular task. Each lab assignment for this class should go into it's own directory. The Linux command to create a directory is mkdir, and to create a directory for this lab assignment you can type mkdir lab1 -- STEP 3 Change your current directory to be the newly created directory by using the Linux command cd command, like this cd lab1 -- STEP 4 -- You can then confirm what directory you are in with the Linux command pwd which should display something like the following back to you: /usr/home/b/576/ tuc49583/lab1 -- STEP 5 -- Identify what editor you will be using to enter your source code. There are at least three editors you can use: nano vi emacs Beginners should use nano. You re free to use whatever you want, however, as long as the lab instructor approves it. Assuming you are using nano, you would now type the following at the Linux prompt to being creating your source code file: nano lab1.c You are now in nano screen editing mode and can use the arrow keys to move the cursor and type in your C source code. Your screen should look like the following: Page 5 of 11

In this example, the line at the top of the screen says you're editing in GNU nano 2.2.6, and the file you are editing is called lab1.c, and on the third line from the bottom, you're reminded that you are creating a new file, rather than editing an existing file. The bottom two rows of the example screen are the editor control functions, and they all begin with the caret character, which is ^ The caret is the character you get by holding SHIFT and pressing the 6 key on the top row of the keyboard. But that s not how you access the nano controls. To use the nano control functions, hold down the CONTROL key on the keyboard and type the letter you see after the caret. For example, to exit nano, which is the tag on the last row of the screen on the far left, you would hold down the CONTROL key and type the letter X. If you do that, the nano program ends and returns you to the Linux prompt. To go back into the editor, simply type nano lab1.c again and the screen above should reappear. Just as a test, to make sure we can enter and exit the editor with confidence, type a few lines from the first lab assignment. Your screen should look like the following: Page 6 of 11

Before you spend a lot of time typing, let's save this C source code file and make sure we can see it in Linux. To save the file, press the CONTROL key and then press X. When you do that, you will see a prompt at the bottom of the screen, as shown below: Type the letter 'y' (no control key) to answer yes to this nano prompt and save the file. Nano will then prompt you with the following: Page 7 of 11

File Name to Write: lab1.c at which point you can just press the return key. This will end the nano editing session, and you will be returned to Linux and see the Linux prompt. Let's confirm the file has been saved in the computer! If you now type the Linux command ls at the linux prompt, you should see something like this: [astro] ~/lab1 % ls lab1.c [astro] ~/lab1 % The command 'ls' lists the files in the current directory. You can see that you created a file called lab1.c. You can see more detailed information about the file by using the l flag on ls (that s the letter L, not the number one). [astro] ~/lab1 % ls -l -rw------- 1 tuc49583 temple 780 Aug 5 23:58 lab1.c [astro] ~/lab1 % Here, we see the details, including the date and time the file was last updated (August 5th of the current year at 11:58 PM) and the number of bytes in the file (780 bytes). The operating system actually keeps additional information about the file that isn t shown here, but thats more of an advanced topic, so we won t discuss it further at this time. You can also see the contents of the file from the Linux prompt, without going into the editor, by typing [astro] ~/lab1 % more lab1.c #include <stdio.h> #include <stdlib.h> /* * Location: Temple University CIS 1057 * Programmer: Ray Lauff... [astro] ~/lab1 % Page 8 of 11

-- STEP 6 -- You can now return to the nano text editor and enter in the rest of your C source code, one line at a time. You might want to occasionally save it out to disk, just in the event there is a server or network interruption and your ssh session becomes disconnected. This is called 'saving your work'. When you are done typing in all your C source code, save your file as we learned above. -- STEP 7 -- Now it's time to have the computer inspect your C source code and see if it understands it all. This is called invoking the compiler. Compile and run the program at the Linux prompt using the command cc lab1.c If the compiler displays messages about things it doesn't like in your C source code, you need to go back in to the editor and correct them (back to step 5). If you do not get any messages displayed about your C source code, then you can use the ls command now and you should see two files in the directory, lab1.c and a.out. Later in futer labs, we might use other compiler invocations. Some common ones are cc -lm lab4.c cc -std=c99 lab5.c cc -std=c99 -g lab5.c cc -std=c99 function1.c function2.c function3.c lab6.c -- STEP 8 -- To run your program, and to have the computer actually follow the instructions in your C code, enter./a.out at the Linux prompt. This isn't technically a Linux command, but the name of the file the compiler created by reading your C program in the previous step. Linux will accept a file name at the command line as a program to run, and as long as it's been compiled correctly, the computer will execute it. When you enter the file name above (a.out), your program should begin running. If it runs correctly, great! Then you can continue to the next step. If it doesn't do what you wanted it to do, you need to go back to step 5 and edit the C source code. Page 9 of 11

-- STEP 9 -- Once the program works correctly, be sure to make a COPY of your work on a flash drive or email it or sftp copy it to another computer. The Linux command to email a copy of the file to tuc49583@temple.edu is cat lab1.c mail -s lab 1 source code tuc49583@temple.edu Please do not use this address as your 'backup' email address. Use your own address instead. You should only send programs that are complete and ready to be graded to the email address labwork@temple.edu. This is how you will receive a grade for your lab. It is the pipe character, between the c in lab1.c and the m in mail in the command above. Usually located below the backspace or delete key on the keyboard, you have to shift to type it.! You can also copy your file to other computer accounts using the scp command. The Linux command to copy the file to your computer science account is scp lab1.c tuc49583@cis-linux2.cis.temple.edu: In this case, replace the tuc49583 with your AccessNet account name. You may also print out a hardcopy of your program on the printer. Check with the lab instructor to get the correct command to print -- it is dependant on the lab room you're in. Page 10 of 11

-- STEP 10 -- Now that the program is working correctly, we want to save a copy of exaclty what happens when you run it so it can be graded. We want to save the output in a file named lab1_output.txt. To do this under Linux, use the Linux 'script' command like this. script lab1_output.txt If you type this command correctly, you will get a message like the following: Script started, output file is lab1_output.txt Then, run your program again by typing./a.out and when your program is done, end the script by typing exit at which point you should see the message Script done, output file is lab1_output.txt This means the file has been successfully created. For submitting labs, you will want to start the script, run your program, answer the prompts, see the output, and then run the program again, answer the prompts, etc. You need to run the program three times using different input values and then end the script. Then all three runs will be recorded in one script file. -- STEP 11 -- To mail both your C program and your script output file to be graded, use the command cat lab1.c lab1_output.txt mail -s "Lab assignment 1" labwork@temple.edu All done! Page 11 of 11