CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Similar documents
CS Fundamentals of Programming II Fall Very Basic UNIX

CS CS Tutorial 2 2 Winter 2018

Mills HPC Tutorial Series. Linux Basics I

Introduction to the Linux Command Line

CISC 220 fall 2011, set 1: Linux basics

1 Getting Started with Linux.

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

Using the Zoo Workstations

Parallel Programming Pre-Assignment. Setting up the Software Environment

Introduction: What is Unix?

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

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

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

Week 2 Lecture 3. Unix

Outline. Structure of a UNIX command

Getting started with Hugs on Linux

CMSC 104 Lecture 2 by S Lupoli adapted by C Grasso

Linux File System and Basic Commands

CS4350 Unix Programming. Outline

Operating Systems and Using Linux. Topics What is an Operating System? Linux Overview Frequently Used Linux Commands

CENG 334 Computer Networks. Laboratory I Linux Tutorial

INSE Lab 1 Introduction to UNIX Fall 2017

CST8207: GNU/Linux Operating Systems I Lab Six Linux File System Permissions. Linux File System Permissions (modes) - Part 1

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

Getting Started With UNIX Lab Exercises

Unix Tutorial Haverford Astronomy 2014/2015

Hands-on Keyboard: Cyber Experiments for Strategists and Policy Makers

Working with Basic Linux. Daniel Balagué

Unix background. COMP9021, Session 2, Using the Terminal application, open an x-term window. You type your commands in an x-term window.

Session 1: Accessing MUGrid and Command Line Basics

A Brief Introduction to Unix

Lab 1 Introduction to UNIX and C

Getting started with Hugs on Linux

Using WestGrid from the desktop Oct on Access Grid

Hitchhiker s Guide to VLSI Design with Cadence & Synopsys

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

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

Introduction to Linux Workshop 1

Linux at the Command Line Don Johnson of BU IS&T

UNLV Computer Science Department CS 135 Lab Manual

MTU Computer Structure

C++ Programming on Linux

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

Some Linux (Unix) Commands that might help you in ENSC351

Introduction to Linux

Unix Basics. Benjamin S. Skrainka University College London. July 17, 2010

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

Operating Systems. Copyleft 2005, Binnur Kurt

Chapter-3. Introduction to Unix: Fundamental Commands

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Due: February 26, 2014, 7.30 PM

15-122: Principles of Imperative Computation

Find out where you currently are in the path Change directories to be at the root of your home directory (/home/username) cd ~

Linux Training. for New Users of Cluster. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

Introduction to Unix and Linux. Workshop 1: Directories and Files

Unix Basics. Systems Programming Concepts

A Brief Introduction to the Linux Shell for Data Science

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

Introduction to Linux

commandname flags arguments

CSC111 Computer Science II

Introduction of Linux

Brief Linux Presentation. July 10th, 2006 Elan Borenstein

Exercise Sheet 2. (Classifications of Operating Systems)

Unix basics exercise MBV-INFX410

Oxford University Computing Services. Getting Started with Unix

Getting Started with UNIX

Linux Survival Guide

Introduction. SSH Secure Shell Client 1

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

UTA Tech Orientation Spring 2019

Unix/Linux Operating System. Introduction to Computational Statistics STAT 598G, Fall 2011

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

INF322 Operating Systems

STA 303 / 1002 Using SAS on CQUEST

UNLV Computer Science Department CS 135 Lab Manual

5/8/2012. Creating and Changing Directories Chapter 7

Unix Workshop Aug 2014

Linux Command Line Primer. By: Scott Marshall

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

Unix Tutorial. Beginner. CS Help Desk: Marc Jarvis (in spirit), Monica Ung, Corey Antoniuk 2015

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

For Dr Landau s PHYS8602 course

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

UNIX File Hierarchy: Structure and Commands

Lab 1 1 Due Wed., 2 Sept. 2015

User Guide Version 2.0

Lab Working with Linux Command Line

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

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

Practical Session 0 Introduction to Linux

Perl and R Scripting for Biologists

Part I. UNIX Workshop Series: Quick-Start

Basic Unix Commands. CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang

Commands are in black

Operating Systems, Unix Files and Commands SEEM

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

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

Introduction to Linux. Fundamentals of Computer Science

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

Transcription:

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX This handout very briefly describes how to use Unix and how to use the Linux server and client machines in the EECS labs that dual boot Windows and Linux (KC 267, KC 265, KC 136). For more information, ask a CS Lab worker, look at the links on the CS 215 course page, or buy a book. EECS Labs (KC 267, KC 265, KC 136) CS Lab (KC 265), KC 267, and KC 136 consist of client machines that dual boot Windows 10 and Ubuntu 16.04LTS Linux. On boot up, the machines will give a menu to choose an operating system. Please reboot the machines properly if you need to switch to the other operating system. There is a Linux server machine named csserver.evansville.edu, that provides login and home directory service for the Linux sides of the client machines. Users with accounts on csserver also may request Samba credentials from Dr. Hwang to map their Linux home directory as a network drive on any Windows machine inside the UE firewall. CS Lab is open 24/7 to authorized students with access provided by a cipher lock. Please notify Dr. Hwang if you want to be authorized to be in the CS Lab after Koch Center closes. The combination to the lock is available from instructors and labworkers. During each semester, there are labworkers with schedules posted outside the CS Lab who can answer questions regarding how to do things in the lab. KC 267 and KC 136 are open during the day and available whenever classes are not scheduled. After hours access to KC 267 and KC 136 is authorized on a case by case basis. See Ms. Vicky Hasenhour if you need after hours access to KC 267 or KC 136. Students are allowed to log into csserver remotely using any terminal client supporting the SSH (secure shell) protocol, such as ssh (Linux) or putty (Windows). While you can log into csserver from a lab client machine using a terminal client, we prefer that you use the Linux side directly (unless a program must be run on csserver specifically) in order to keep the load low on csserver. More information on remote login is given at the end of this handout. Basic UNIX functionality UNIX is a command line oriented operating system. This means that you interact with a computer through a interactive terminal shell and programs are run by typing commands and their arguments at the shell prompt. (It is similar to DOS in this way.) The basic syntax of running any program is: command options arguments where command is the name of the program and the options and arguments are whatever else it needs to run. Options are things that change the way a program behaves, typically they start with - ("dash") and may have arguments of their own (e.g. a file name). Arguments are things that the program will operate on, typically file and directory (the UNIX word for "folder") names. Note that UNIX is case sensitive. Conventionally, most UNIX commands and file/directory names are in all lower case. The UNIX file system is hierarchical. The root directory of the file system is called / ("slash"). Under the root direcctory are various subdirectories. Each user has a home directory under /home, e.g. /home/hwang. When you log in, you are put into your home directory where only you have access to read and write files initially. The default shell on the UE lab machines is bash. This shell supports, among other things, using the up and down arrow keys to access previously typed commands, line editing using emacs style commands, and command completion using the TAB key. (The shell can be changed using the command chsh, if another is preferred.) 01/10/2019 Page 1 of 5 D. Hwang

Files and directories are named using either absolute or relative pathnames. An absolute pathname starts with /, the root directory. A relative pathname is relative to the current directory and can start with a subdirectory name,.. ("dot dot" parent directory),. ("dot" current directory) or ~ ("tilde" home directory). Most commands also will allow wild cards in pathnames. The most common ones used are: * (match 0 or more of any character) and? (match exactly one character). For example, project1.* will match all files starting with project1. and having any extension (e.g., project1.cpp, project1.o, etc.). Likewise, project?.cpp will match any.cpp file that has the name project and one character (e.g., project1.cpp, project2.cpp, etc.). Basic UNIX commands Here is a very brief list of the most commonly used UNIX commands (more or less in the order presented in class) with the most commonly used options and arguments that you will need to know to get started. Unless otherwise noted, all commands may be used on csserver or the client machines. passwd Change password. The program will ask you for your current password, a new password, and then your new password again to confirm. mkdir subdir1 subdir2... Create subdirectories in the current directory. ls options directory List directory. Default is in alphabetical order ignoring hidden files (those starting with a dot). Options include l (long listing format showing permission modes and sizes), a (including hidden dot files), d (directory only). Options can be combined, e.g., ls la will list all files, including hidden files, in long format. chmod newmode name1 name2... Change permission mode. Permissions to access files and directories are granted in three groups (user, group, other) of three rights (read, write, execute). They are represented in a long listing (ls l) as: rwxrwxrwx These permissions can be represented as a 3 digit octal (base 8) number where each right is a bit in the number. In the long listing, a letter (r, w, x) means the bit is set to 1, whereas (minus) means the bit is 0. E.g., 777 would be all rights to all users (rwxrwxrwx), whereas 754 would be all access for the user, read and execute access for the group, and read only access for everyone else (rwxr xr ). By default, your home directory is open for all access to you and closed to all others, i.e., mode 700 (rwx ). All other directories and files are created with all access to you and read only access for everyone, i.e., modes 755 (rwxr xr x) and 644 (rw r r ) for directories and files, respectively. You might want to change the permission mode of your course directories to 700 to prevent anyone from viewing your course files. man command Show the manual page for command. Most commands have man pages. For example, if you wanted to know what other options there are for the ls command, you could type: man ls. cd directory Change to directory. The directory name can be absolute or relative. If run without an argument, it changes to the user's home directory. (I.e., equivalent to cd ~) 01/10/2019 Page 2 of 5 D. Hwang

cp name1 name2 or cp namelist directory Copy a file or directory. The first version copies one file and possibly renames the copy. In the second version, all files in namelist are copied into directory with the same names. To copy a directory, the r option (i.e., recursive copy) must be used. A common idiom is to copy one directory into the current directory which is indicated by using '.' (dot) using the r option. For example, cp r /home/hwang/cs215/examples. will copy the directory /home/hwang/cs215/examples to the current directory. mv name1 name2 or mv namelist directory Move a file or directory. The first version moves one item and can be used to rename it. In the second version, namelist is a list of items to be moved to directory. more filename Display file to screen a page at a time. Typing space will advance to the next page, typing 'b' will go back to previous page, typing 'q' quits the program. emacs filename or vim filename Text editors. The majority of programmers use one of these text editors for creating program source files. Both have vociferous adherents who intensely dislike the other editor. While you can use a another editor (e.g., gedit) if you wish, only emacs and vim are present in nearly every UNIX distribution. The two things that everyone needs to know about each is how to save files (Ctrl x Ctrl s in emacs, :w<enter> in vim) and how to quit the editor (Ctrl x Ctrl c in emacs, :q<enter> in vim). Both editors have built in tutorials (Ctrl h t from within emacs, vimtutor on the command line for vim). Links to several on line tutorials and reference cards are available for each on the course webpage. clang++ options filenames The clang C++ compiler. See separate submission handout regarding use of the compiler. This compiler uses the same options as g++. rm file1 file2... Delete files. Can also be used with rf options to delete non empty directories. (The rmdir command will delete empty directories only.) git <action> The git version control system. See separate handouts and links to on line documentation regarding use of this system. tar options filenames An archive facility that combines multiple files into one file. See separate submission handout regarding use of tar. make target Generate a target from a makefile. If run without any options or arguments, it makes the first target in a file called makefile or Makefile. Typically, the first target in a makefile creates the entire project. See separate handout regarding use of this application. 01/10/2019 Page 3 of 5 D. Hwang

touch file1 file2... Changes the last modified date of files to current date. Useful for forcing make to recreate a target by touching a source file. jobs List programs running in background mode. The job number listed can be used to kill a process using %#. E.g., kill %1 terminates the process of job 1. ps axu List all processes running on the machine. When a program runs it has a process associated with it. Occasionally, you'll need to find out the ID of a process (e.g. to terminate a runaway program). kill job Terminate a process. The job can be specified by PID (process id) or job number (%#) from the jobs listing. Occasionally, this will not work and you will need to use option 9, which says to terminate the process if at all possible. Using Linux in the EECS Labs The client machines run X Windows in Linux. The default GUI is called Unity. Terminal windows can be launched in a variety of ways depending on the GUI, but it can always be done by going to the Dashboard launcher and typing "terminal". If you are using vim as your editor, you will probably want at least two terminal windows, one for editing and one for compiling. If you are using emacs, you will find that emacs launches its own window. This means that it should be run in the background using: emacs filename & The & tells the shell to run emacs in the background and returns control to the shell. By doing this, you can now edit in the emacs window and compile in the terminal window. Using VirtualBox A full Linux distribution may be run in conjunction with Windows on the same machine in two ways. One is to dual boot as the client machines do. The advantage of this method is that Linux is running directly on the hardware, so is a little faster. The disadvantage is that only one operating system is running at time, so the machine must be rebooted to get back to Windows. Another way is to run VirtualBox, an x86 virtual machine, available at http://www.virtualbox.org/. The advantage of this method is that both Windows and Linux are running at the same time. The disadvantage is that the Linux operating system calls are translated into Windows calls, so are a little slower. See the course webpage for more information. Using csserver remotely To access csserver remotely, a terminal client that supports the SSH (secure shell) protocol must be used so that transmitted data is encrypted. (In particular, telnet and ftp transmit passwords in clear text, so are not supported.) For Windows boxes, Putty is a very small (fits on a USB stick) terminal client (available at http://www.chiark.greenend.org.uk/~sgtatham/putty/). The installation puts an icon on the desktop that can be used to launch Putty. Type csserver.evansville.edu as the machine to connect to, and confirm the protocol being used is SSH before connecting. A dialog box asking about unknown host key will appear (usually only the first 01/10/2019 Page 4 of 5 D. Hwang

time); just click 'Yes'. Then a terminal window will appear and you will be prompted for your username and password. It probably will be convenient to log into the server twice so that you can edit in one window and compile in another. To transfer files between a local Windows host and csserver (e.g. in order to locally print a file or to submit a project), use WINSCP (available at http://winscp.net/eng/index.php). For Linux boxes, ssh usually is available. To use it, type the following into a terminal window: ssh username@csserver.evansville.edu where username is your csserver user name. (If your local user name is the same as csserver's, you can leave off the username@ part.) The SSH server on csserver is configured to forward X packets, so you can use your local machine like a lab machine by providing the X option to ssh. However, sometimes a network is too slow to support interactive graphics and doing plain text sometimes works better. In particular, if you use emacs, you might want to start it without a new window, which can be accomplished using the nw option. On a local Linux, transfer files to/from csserver using scp which has syntax like cp. Remote names are prefixed with username@remotemachinename: and are relative to the user home directory. For example, scp r username@csserver.evansville.edu:/home/hwang/cs215/examples. will copy all the directory /home/hwang/cs215/examples on csserver to the current directory on the local machine. 01/10/2019 Page 5 of 5 D. Hwang