Introduction to UNIX. Introduction EECS l UNIX is an operating system (OS). l Our goals:

Similar documents
Introduction to UNIX. Introduction. Processes. ps command. The File System. Directory Structure. UNIX is an operating system (OS).

Introduction to UNIX. CSE 2031 Fall November 5, 2012

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

Linux Command Line Primer. By: Scott Marshall

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

Introduction: What is Unix?

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

Perl and R Scripting for Biologists

The Unix Shell. Pipes and Filters

Unix Basics. Systems Programming Concepts

Lab 2: Linux/Unix shell

DATA 301 Introduction to Data Analytics Command Line. Dr. Ramon Lawrence University of British Columbia Okanagan

Why learn the Command Line? The command line is the text interface to the computer. DATA 301 Introduction to Data Analytics Command Line

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

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

A Brief Introduction to Unix

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

System Administration

Introduction to Linux

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2)

Computer Systems and Architecture

Computer Systems and Architecture

3/8/2017. Unix/Linux Introduction. In this part, we introduce. What does an OS do? Examples

Introduction To. Barry Grant

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

CSC UNIX System, Spring 2015

Introduction to Linux

Useful Unix Commands Cheat Sheet

System Programming. Introduction to Unix

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

Common File System Commands

First of all, these notes will cover only a small subset of the available commands and utilities, and will cover most of those in a shallow fashion.

The Unix Shell & Shell Scripts

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

Linux Shell Script. J. K. Mandal

Part 1: Basic Commands/U3li3es

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

UNIX Quick Reference

5/20/2007. Touring Essential Programs

unix intro Documentation

Introduction to the Linux Command Line January Presentation Topics

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

UNIX Essentials Featuring Solaris 10 Op System

Read the relevant material in Sobell! If you want to follow along with the examples that follow, and you do, open a Linux terminal.

2) clear :- It clears the terminal screen. Syntax :- clear

Basic Linux (Bash) Commands

Chap2: Operating-System Structures

Unix Processes. What is a Process?

EECS2301. Lab 1 Winter 2016

Introduction to UNIX Shell Exercises

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

Files and Directories

Introduction To Linux. Rob Thomas - ACRC

Introduction to Linux

Scripting Languages Course 1. Diana Trandabăț

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:

Unix Tools / Command Line

Introduction to the UNIX command line

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

Introduction to Linux Part 1. Anita Orendt and Wim Cardoen Center for High Performance Computing 24 May 2017

Linux Command Line Interface. December 27, 2017

Command-line interpreters

Getting Started With UNIX Lab Exercises

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

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

CENG 334 Computer Networks. Laboratory I Linux Tutorial

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

Introduction to Linux Organizing Files

Mills HPC Tutorial Series. Linux Basics I

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

Advanced Linux Commands & Shell Scripting

(a) About Unix. History

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

Reading and manipulating files

On successful completion of the course, the students will be able to attain CO: Experiment linked. 2 to 4. 5 to 8. 9 to 12.

Recap From Last Time:

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

Command Line Interface The basics

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

BGGN 213 Working with UNIX Barry Grant

Introduction of Linux

Introduction to Linux

Introduction to Linux. May 9, 2010 Isaac Ye SHARCNET York University

Lab #2 Physics 91SI Spring 2013

CSCI 2132 Software Development. Lecture 5: File Permissions

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

UNIX Basics. UNIX Basics CIS 218 Oakton Community College

Linux Bootcamp Fall 2015

Exercise 1: Basic Tools

Chapter-3. Introduction to Unix: Fundamental Commands

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

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

CSCI 2132 Software Development. Lecture 4: Files and Directories

Lec 1 add-on: Linux Intro

Introduction to the Linux Command Line

Command Line Interface Techniques

Chapter 4. Unix Tutorial. Unix Shell

Set 1 MCQ Which command is used to sort the lines of data in a file in reverse order A) sort B) sh C) st D) sort -r

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

Transcription:

Introduction to UNIX EECS 2031 13 November 2017 Introduction l UNIX is an operating system (OS). l Our goals: Learn how to use UNIX OS. Use UNIX tools for developing programs/ software, specifically shell programming. 2 1

Processes l Each running program on a UNIX system is called a process. l Processes are identified by a number (process id or PID). l Each process has a unique PID. l There are usually several processes running concurrently in a UNIX system. 3 ps command # a = list all processes 4 2

The File System l Directory structure l Current working directory l Path names l Special notations 5 Directory Structure 6 3

Current Working Directory l Every process has a current working directory. l In a shell, the command ls shows the contents of the current working directory. l pwd shows the current working directory. l cd changes the current working directory to another. 7 Path Names A path name is a reference to something in the file system. A path name specifies the set of directories you have to pass through to find a file. Directory names are separated by '/' in UNIX. Path names beginning with '/' are absolute path names. Path names that do not begin with '/' are relative path names (start search in current working directory). 8 4

Special Characters l. means the current directory l.. means the parent directory cd.. cd../notes l ~ means the home directory cat ~/lab3.c l To go directly to your home directory, type cd 9 Frequently Used Terminal Keystrokes l Interrupt the current process: Ctrl-C l End of file: Ctrl-D l Read input (stdin) from a file o a.out < input_file l Redirect output (stdout) to a file o ls > all_files.txt # overwrites all_files.txt l Append stdout to a file o ls >> all_files.txt # append new text to file 5

Wildcards (File Name Substitution) l Goal: referring to several files in one go. l? match single character ls ~/C2031/lab5.??? lab5.doc lab5.pdf lab5.out l * match any number of characters ls ~/C2031/lab5.* l [ ] match any character in the list enclosed by [ ] ls ~/C2031/lab[567].c lab5.c lab6.c lab7.c l We can combine different wildcards. ls [e]*.c enum.c ex1.c ex2.c 11 File Manipulation Commands ls, cp, mv, rm touch pwd, mkdir, rmdir cd chmod, chown, chgrp find 12 6

find command Search from the current directory: % find. -name "ex1.c"./ptr2ptr/ex1.c./ex1.c % find. -name "e*.c"./midterm/err.c./ex2.c./ptr2ptr/ex2.c./ptr2ptr/ex1.c./enum.c./ex1.c Search from the home directory: % find ~ -name "ex1.c" /cs/home/utn/temp_2031/misc/ex1.c /cs/home/utn/demo_2031/ptr2ptr/ex1.c /cs/home/utn/demo_2031/ex1.c Search from the specified directory: % find./test1/archive/ -name "*.c"./test1/archive/convertmain.c 13 Commonly Used Commands l Get on-line help with man man chgrp l Some commonly used commands cat, more who grep echo date sort wc ps, kill history 14 7

cat, more, tail % cat phone_book Yvonne 416-987-6543 Amy 416-123-4567 William 905-888-1234 John 647-999-4321 Annie 905-555-9876 % more phone_book Similar to cat, except that the file is displayed one screen at a time. % tail myfile.txt Display the last 10 lines % tail -5 myfile.txt Display the last 5 lines % tail -1 myfile.txt Display the last line 15 echo l When one or more strings are provided as arguments, echo by default repeats those strings on the screen. % echo This is a test. This is a test. l It is not necessary to surround the strings with quotes, as it does not affect what is written on the screen. l If quotes (either single or double) are used, the quotes are not repeated on the screen. % echo This is a test. This is a test. l To display single/double quotes, use \ or \ 16 8

echo (cont.) % echo a \t b a t b % echo 'a \t b' a b % echo "a \t b" a b 17 UNIX Filter grep % grep char *.c arr.c: char s[] = "2031"; char.c: char c; char.c: c = getchar(); % grep 1302ESC cse*/lab3.c % grep i ChaR *.c arr.c: char s[] = "2031"; char.c: char c; char.c: c = getchar(); % grep v char *.c Search for lines that do not contain pattern char. % grep bea[nm] *.txt Search for lines that contain either bean or beam. % grep '[0-9][0-9][0-9]' *.c Search for lines that contain a sequence of 3 (or more) digits. 18 9

grep (cont.) % grep n char *.c Also display the line numbers. % grep [3] *.c % grep 3 *.c Search for lines that contain digit 3. % grep \[3\] *.c Search for lines that contain string [3]. % grep \[ *.c 19 wc % wc enum.c 14 37 220 enum.c % wc -c enum.c 220 enum.c % wc [e]*.c 14 37 220 enum.c 17 28 233 ex1.c 21 46 300 ex2.c 52 111 753 total % wc -w enum.c 37 enum.c % wc -l enum.c 14 enum.c 20 10

sort % cat phone_book Yvonne 416-987-6543 Amy 416-123-4567 William 905-888-1234 John 647-999-4321 Annie 905-555-9876 % sort phone_book Amy 416-123-4567 Annie 905-555-9876 John 647-999-4321 William 905-888-1234 Yvonne 416-987-6543 Try these options: sort r reverse normal order sort n numeric order sort nr reverse numeric order sort f case insensitive sort k 2 sort on column 2 21 cmp, diff % cat phone_book Yvonne 416-987-6543 Amy 416-123-4567 William 905-888-1234 John 647-999-4321 Annie 905-555-9876 % cat phone_book2 Yvonne 416-987-6543 Amy 416-111-1111 William 905-888-1234 John 647-999-9999 Annie 905-555-9876 % cmp phone_book phone_book2 phone_book phone_book2 differ: char 30, line 2 % diff phone_book phone_book2 2c2 < Amy 416-123-4567 --- > Amy 416-111-1111 4c4 < John 647-999-4321 --- > John 647-999-9999 22 11

who % who ossama pts/13 Nov 7 00:22 (ip-198-96-36-11.dynamic.yorku.ca) hoda pts/21 Nov 4 16:49 (gomez.cs.yorku.ca) gordon pts/24 Nov 5 10:40 (bas2-toronto08-1096793138.dsl.bell.ca) minas pts/29 Nov 2 14:09 (monster.cs.yorku.ca) jas pts/37 Oct 18 12:36 (brayden.cs.yorku.ca) utn pts/93 Nov 7 12:21 (bas2-toronto44-1177753778.dsl.bell.ca) l User name l Terminal associated with the process l Time when they logged in 23 kill % ps a PID TTY TIME CMD 2117 pts/24 00:00:00 pine 2597 pts/79 00:00:00 ssh 5134 pts/67 00:00:34 alpine 7921 pts/62 00:00:01 emacs 13963 pts/24 00:00:00 sleep 13976 pts/43 00:00:00 sleep 13977 pts/93 00:00:00 ps 15190 pts/90 00:00:00 vim 24160 pts/44 00:00:01 xterm... % kill 7921 24 12

history % history 10 323 12:45 ls 324 12:47 cd Demo_2031/ 325 12:48 ls 326 12:48 m ex1.c 327 12:49 who 328 12:50 history 10 329 12:52 ls -a 330 12:56 ls Stack/ 331 12:57 ls 332 12:57 history 10 25 Pipes l Pipe: a way to connect the output of one program to the input of another program without any temporary file. l Pipeline: connection of two or more programs through pipes. l Examples: ls wc w # count number of files who sort # sort user list who wc l # count number of users who grep utn # look for user utn ps a grep 'emacs # look for process emacs 26 13

NEVER-DO List in UNIX l Never switch off the power on a UNIX computer. You could interrupt the system while it is writing to the disk drive and destroy your disk. Other users might be using the system. l Avoid using * with rm such as rm *, rm *.c l Do not name an important program core. When a program crashes, UNIX dumps the entire kernel image to a file called core. Many scripts go around deleting these core files. l Do not name an executable file test. There is a Unix command called test. 27 Next time l UNIX Basics 2 l Writing Shell Scripts 28 14