CSC111 Computer Science II

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

Lab 1 Introduction to UNIX and C

Lab 1 Introduction to UNIX and C

CMSC 104 Lecture 2 by S Lupoli adapted by C Grasso

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

CS CS Tutorial 2 2 Winter 2018

Exercise 1: Basic Tools

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

Laboratory 1 Semester 1 11/12

Helpful Tips for Labs. CS140, Spring 2015

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

Parallel Programming Pre-Assignment. Setting up the Software Environment

CSE 351. Introduction & Course Tools

Introduction to the Linux Command Line

User Guide Version 2.0

1. The Mac Environment in SIE 1222

Intermediate Programming, Spring Misha Kazhdan

Practical Session 0 Introduction to Linux

Hand-on Labs for Chapter 1 and Appendix A CSCE 212 Introduction to Computer Architecture, Spring

1. The Mac Environment in Sierra Hall 1242

COMP s1 Lecture 1

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

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

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

CMSC 201 Spring 2017 Lab 01 Hello World

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

AMS 200: Working on Linux/Unix Machines

9 and 11-Jan CSCI 4152/6509 Natural Language Processing Lab 1: FCS Computing Environment, SVN Tutorial. FCS Computing Environment, SVN Tutorial

Programming and Data Structure Laboratory (CS13002)

Getting started with UNIX/Linux for G51PRG and G51CSA

Introduction: What is Unix?

CMSC 201 Spring 2018 Lab 01 Hello World

Short Read Sequencing Analysis Workshop

23. Check that hello.txt now contains (substitute your info for mine): hello rcwhaley: Dr. Whaley

Introduction to Computing V - Linux and High-Performance Computing

Programming the DMCC in C

Introduction to Linux

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

Introduction to Supercomputing

C++ Programming on Linux

Using the Zoo Workstations

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

CS Fundamentals of Programming II Fall Very Basic UNIX

15-122: Principles of Imperative Computation

The Command Line. Matthew Bender. September 10, CMSC Command Line Workshop. Matthew Bender (2015) The Command Line September 10, / 25

Tutorial 1: Unix Basics

Introduction to Linux for BlueBEAR. January

ECE 2036 Lab 1: Introduction to Software Objects

27-Sep CSCI 2132 Software Development Lab 4: Exploring bash and C Compilation. Faculty of Computer Science, Dalhousie University

23. Check that hello.txt now contains (substitute your info for mine): hello rcwhaley: Dr. Whaley

EECS Software Tools. Lab 2 Tutorial: Introduction to UNIX/Linux. Tilemachos Pechlivanoglou

Physics REU Unix Tutorial

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

Linux hep.wisc.edu

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

Lecture 01 - Working with Linux Servers and Git

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)

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

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

CSCI 4152/6509 Natural Language Processing. Lab 1: FCS Computing Environment

Introduction to Linux

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

COMS 6100 Class Notes 3

CENG393 Computer Networks Labwork 1

Development Environment & Linux Guide

Session 1: Accessing MUGrid and Command Line Basics

Lab 2 Building on Linux

Linux/Cygwin Practice Computer Architecture

Recitation #1 Boot Camp. August 30th, 2016

PRINCIPLES OF OPERATING SYSTEMS

You should see something like this, called the prompt :

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

Introduction to Linux Environment. Yun-Wen Chen

Mills HPC Tutorial Series. Linux Basics I

Problem Set 1: Unix Commands 1

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

Working with Basic Linux. Daniel Balagué

LAB 0: LINUX COMMAND LINE AND SVN

Systems Programming and Computer Architecture ( ) Exercise Session 01 Data Lab

CSCE 212H, Spring 2008, Matthews Lab Assignment 1: Representation of Integers Assigned: January 17 Due: January 22

Unit 10. Linux Operating System

Exploring UNIX: Session 3

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

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

Unix and C Program Development SEEM

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

Unix Workshop Aug 2014

Introduction: The Unix shell and C programming

Unix Tutorial Haverford Astronomy 2014/2015

Linux and Git Boot Camp

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

LAB #5 Intro to Linux and Python on ENGR

CS 246 Winter Tutorial 1

Parallel Programming Pre-Assignment. Setting up the Software Environment

Connecting to ICS Server, Shell, Vim CS238P Operating Systems fall 18

Linux Command Line Primer. By: Scott Marshall

For Dr Landau s PHYS8602 course

Python for Astronomers. Week 1- Basic Python

Introduction to Linux Workshop 1

Transcription:

CSC111 Computer Science II Lab 1 Getting to know Linux Introduction The purpose of this lab is to introduce you to the command line interface in Linux. Getting started In our labs If you are in one of our labs, you just have to use your CS credentials to log into the machine in front of you. If you don t have login id and password, send an email to support@cs.ship.edu. In Windows/Mac Getting to our servers from your Windows or Mac machine just take a few steps. You need a program to connect to our server (sloop.cs.ship.edu). Linux or Mac users can use Terminal and connect to the server as follows: ssh userid@sloop.cs.ship.edu It will ask you for your password and then you will be in. Windows users can pick putty to create an ssh (secure shell) session on our server (sloop.cs.ship.edu). If you use putty, this is what the settings should be: Putty will then ask you who you want to log in as that is where you give your CS credentials.

* You can also use a Virtual Private Network (VPN) connection to get behind the campus firewall. You can find instructions for how to do that at the department website (https://web.cs.ship.edu/current- students/departmental- resources/) Using a Linux VM If you prefer, you can do all of your coding on your personal machine in a linux virtual machine. You can learn how to do that from our department website at https://web.cs.ship.edu/current- students/departmental- resources/. However, you should be aware that not all linux installations run exactly the same way. If you develop your code on your machine, you MUST copy it to sloop and ensure that it works there before you submit it for grading. Running on sloop is the ultimate measure of whether it works. Directories & Files In Linux, the things you called folders in Windows are called directories and you are always in a directory (which is called your working directory ). That means that, unless you specify otherwise, linux will expect the files that you reference are in that directory. Working directory When you first log into the system, you start in your home directory in other words, your home directory is your working directory. You can see what directory you are in by entering the pwd (print working directory) command. When you first log in, pwd should return something that looks like: /home/userid That is the path that is your home directory, but there isn t any reason that you need to memorize that. Fortunately, you can always use ~ to reference your home directory. You can create directories with the mkdir command. Let s suppose that you want to create a directory to hold all of the stuff for this class. You can create that directory (within your current working directory) by entering mkdir spring2018 Once you have created a directory, you can make it be your working directory (which is often referred to a going into it using the cd (change directory) command. Move into the directory you just created by entering cd spring2018 Use the pwd command to see that your working directory has been changed. You can always get back to your home directory by typing cd to move back to your home directory and verify where you are with the pwd command.

You can nest directories like folders can be inside folders in Windows. Move into your spring2018 directory and use the mkdir command to create subfolders named csc111, labs, and lab1. Then move into the lab1 folder. At this point, pwd should return something like /userid/spring2018/csc111/labs/lab1 There are two more special folders that you need to know about:. means the current working directory and.. means the directory containing the current working directory (sometimes called the parent directory). That means, that entering This is giving you the path to the directory. The first / is the topmost directory in the system and each subsequent section of this path is a subdirectory. cd.. will move you to the parent directory and doing that again will take you back to your home directory. In review, we have learned about these special directory aliases: Alias Meaning ~ your home directory. the current working directory.. the directory containing the current working directory ls and man commands You can see all of the files in your current working directory with the ls command. ls entered by itself will give you a list of the visible files and directories in the working directory, but there are also options that you can put on that command. For example, it is common to enter ls al to list the files in the working directory. The - al are options on the command: the a means all (show all of the files) and the l means long listing format which gives a lot more information about each file (file permissions, size, date modified). Move to your home directory and enter ls al to see what files are in that directory. You may see other things, you should definitely see the csc111 directory you created earlier. At this point, you can see that the general structure of linux commands is <command> <options following a dash> <other arguments>

When you want to what options and arguments are valid for a command, you can enter man <command> to see those details. Enter man ls to see the details about the ls command. Note that hitting the q key will get you out of the man entry. Look at the output from that ls al and the man entry for ls more carefully. See if you can figure out what the d in the first column means what the next 9 characters mean what are the units on the size of the file is the time stamp modification or creation Also, compare the files/directories listed in the ls and ls al commands to see what the all in the a option really means. Editors You need to pick an editor that you like. The obvious choices are: vim, pico, nano, and emacs. Pico and nano are simple equivalents of notepad completely language unaware. While vim (an enhanced version of vi) and emacs will require some extra time to learn, they offer syntax coloring like you are used to with Eclipse. Here are some tutorials to help you play with vim and emacs: vim: http://www.openvim.com/tutorial.html (except that we can use the arrow keys for movement) emacs: http://www2.lib.uchicago.edu/keith/tcl- course/emacs- tutorial.html (note that emacs creates another window, so it may not run nicely when you are remotely connected to sloop) File commands You can use commands to manipulate your files in linux. Use pwd and cd to put yourself in your Lab1 directory. Here are the important file commands (things in <> must be replaced with the name of the files you are manipulating). Do each of the examples in this table and use the ls command to see its effects. Command Meaning Example touch <f1> create a file with a given name touch foo cp <f1> <f2> copy a file from one place to cp foo fee another mv <f1> <f2> move a file from one place to mv foo fuu another rm <f1> remove a file rm fuu Remember the special directory aliases we covered above and figure out what these commands would do:

cp foo.. mv fee.. cp foo ~ touch../tmp mv../tmp. The only thing left is to remove directories. There are two ways to do that: rm r <directory> will recursively remove everything in a directory (that directory, all of its files, and all of the directories underneath it. rmdir <directory> will remove a directory, but only if it is empty. You need to be careful with - f option since it won t double- check with you if you really want to delete/remove files/directories. Your First C Program Using the editor you selected, edit a file named hello.c and make it contain this code: #include <stdio.h> int main( ) { printf("welcome to CS2!\n"); } return 0; * C is case- sensitive. Compile this program using this command: gcc hello.c Linux contains many tricks to make repeating commands easier. You can use up and down arrows to scroll through the commands you have entered recently. Also, you can use the! (which we pronounce bang ) to get the most recent command that started with something. For example,!gcc would give you the most recent command that started with gcc That will create a default executable file named a.out that you can run using:./a.out Remember that the. means the current directory. If you would like to specify the name of the executable file the compiler creates, you can compile with this command: gcc o hello hello.c which would name the executable file hello (which you can change to be whatever you like).

Standard C Format in CSC111 /* CSC111 Computer Science II Lab 1 Getting to Know Linux: lab1a.c Programmer: Your Name Professor: Dr. Lee File Created: Jan 24, 2018 File Updated: Jan 24, 2018 */ #include <stdio.h> #define N 100 int main() { int i; i = 5; // You can also declare and assign value as int i = 5; printf( Yes, this is your fantastic playground!!!\n ); printf( What is N? %d\n, N); printf( What is i? %d\n, i); printf( What is N * i? %d\n, N*i); // print out the constant N on the screen // print out the value of integer i on the screen // print out the value of N*i on the screen return 0; } When you have command line inputs: int main(int argc, char *argv[]) OR int main(int argc, char **argv) integer type argc returns the number of arguments character string argv[] has each argument in the position starting 0, 1, 2,... argv[0], argv[1], argv[2], etc.

/* CSC111 Computer Science II Lab 1 Getting to Know Linux: lab1b.c Programmer: Your Name Professor: Dr. Lee File Created: Jan 24, 2018 File Updated: Jan 24, 2018 */ #include <stdio.h> int main(int argc, char *argv[]) { int i; printf("input? "); scanf("%d", &i); // reads an integer; stores into i printf("what the value in i? %d \n", i); printf("argc? %d\n", argc); printf("argv[0]? %s\n", argv[0]); printf("argv[1]? %s\n", argv[1]); printf("argv[2]? %s\n", argv[2]); // print out the value of argc // print out the value in argv[0] // print out the value in argc[1] // print out the value in argc[2] return 0; } How to Compile gcc - o lab1b lab1b.c How to Run./lab1b What Would Be