Lecture 3. Unix. Question? b. The world s best restaurant. c. Being in the top three happiest countries in the world.

Similar documents
Introduction: What is Unix?

CISC 220 fall 2011, set 1: Linux basics

CS246 Spring14 Programming Paradigm Notes on Linux

Welcome to Linux. Lecture 1.1

EECS2301. Lab 1 Winter 2016

Essential Linux Shell Commands

The Unix Shell & Shell Scripts

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

Introduction to Linux

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

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

Operating Systems. Copyleft 2005, Binnur Kurt

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

Mills HPC Tutorial Series. Linux Basics I

Perl and R Scripting for Biologists

Introduction to Cygwin Operating Environment

Introduction to Linux Basics

Practical Computing-II. Programming in the Linux Environment. 0. An Introduction. B.W.Gore. March 20, 2015

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

EECS 470 Lab 5. Linux Shell Scripting. Friday, 1 st February, 2018

Introduction to Linux

UNIX Basics. UNIX Basics CIS 218 Oakton Community College

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Mauro Ceccanti e Alberto Paoluzzi

Introduction to Linux

Overview of Unix / Linux operating systems

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

Introduction to Linux

Unix Handouts. Shantanu N Kulkarni

Introduction to Linux

Unix System Architecture, File System, and Shell Commands

CENG 334 Computer Networks. Laboratory I Linux Tutorial

System Programming. Introduction to Unix

Linux & Shell Programming 2014

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Esercitazione Introduzione al linguaggio di shell

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

CENG393 Computer Networks Labwork 1

Files

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

Introduction to the Linux Command Line

Linux Command Line Interface. December 27, 2017

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

Lecture 01: welcome and intro what LSD and Unix have in common

Linux for Beginners. Windows users should download putty or bitvise:

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

Common UNIX Commands. Unix. User Interfaces. Unix Commands Winter COMP 1270 Computer Usage II 9-1. Using UNIX. Unix has a command line interface

(a) About Unix. History

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

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

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

Introduction to Linux

ScazLab. Linux Scripting. Core Skills That Every Roboticist Must Have. Alex Litoiu Thursday, November 14, 13

UNIX Kernel. UNIX History

LING 408/508: Computational Techniques for Linguists. Lecture 5

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

Introduction to Linux

Brief Linux Presentation. July 10th, 2006 Elan Borenstein

Linux Refresher (1) 310/ Fourth Workshop on Distributed Laboratory Instrumentation Systems (30 October - 24 November 2006)

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

Introduction to Linux

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

PROGRAMMAZIONE I A.A. 2015/2016

Unix basics exercise MBV-INFX410

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

CSC209. Software Tools and Systems Programming.

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

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

Introduction to UNIX I: Command Line 1 / 21

GNU/Linux Course Lesson 1. Puria Nafisi

Unix/Linux: History and Philosophy

Scripting Languages Course 1. Diana Trandabăț

Unix Introduction to UNIX

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Introduction to Linux Basics Part I. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

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

Introduction to Linux (Part I) BUPT/QMUL 2018/03/14

Introduction Into Linux Lecture 1 Johannes Werner WS 2017

EE516: Embedded Software Project 1. Setting Up Environment for Projects

The UNIX operating system is a set of programs that act as a link between the computer and the user.

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Introduction to Linux. Roman Cheplyaka

LAB 8 (Aug 4/5) Unix Utilities

Introduction to Unix: Fundamental Commands

Self-test Linux/UNIX fundamentals

CSE 390a Lecture 1. introduction to Linux/Unix environment

I/O and Shell Scripting

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

UNIX Concepts COMPSCI 386

Introduction. Let s start with the first set of slides

Computer Systems and Architecture

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

UNIX / LINUX - GETTING STARTED

Part 1: Basic Commands/U3li3es

CS197U: A Hands on Introduction to Unix

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

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

Command-line interpreters

Introduction to UNIX and Linux: Lecture 1

LAB 8 (Aug 4/5) Unix Utilities

Getting started with Hugs on Linux

Transcription:

Lecture 3 Unix Question? Denmark is famous for? a. LEGO. b. The world s best restaurant. c. Being in the top three happiest countries in the world. d. Having the highest taxes in Europe (57%). e. All of the above.

Announcements There are drop-in help sessions in Reynolds 001/002 (right after lectures). There are TAs who are dedicated just to private tutoring sessions. The tutoring times can be booked from the course website and are free to the students. There are times available beginning next week and anyone who is feeling even a tiny bit overwhelmed should take advantage of the tutoring. If the students don't use it we'll stop offering it. Q&A Do you have a question? (I may have an answer)

OS Computers are closed boxes, hiding the command line and lower level features. rm what s? vs. OS The Operating System is a resource manager. Many different types of operating system, e.g. Windows, OSX, Unix/Linux.

Unix Unix Unix is a multi-user, multi-tasking environment, offering stability, portability and powerful networking capabilities. Unix was created by Ken Thompson and Dennis Ritchie at AT&T in the early 1970s. Evolved from UNICS (Uniplexed Information and Computing System) written in assembler.

Unix-history Incarnations? Berkeley Software Distribution (BSD) Solaris (Sun) Linux - a free open source UNIX OS originally developed by Linus Torvalds in 1991. Mac OSX - based on BSD, (Berkeley Software Distribution) version of Unix.

Importance? C and Unix evolved together. Unix kernel was re-written in C. Benefits of Unix? The kernel itself is relatively small. Can be built specifically for the platform it runs on (OSX), or usable on anything, such as a wristwatch (Linux). Scales well. Can support fully-featured GUI, yet maintains the command-line.

Limitations of Unix? Too many choices for distributions (Linux). Lacks some widely used software (e.g. Photoshop). Architecture Applications Shell Kernel Hardware

Kernel Interacts with hardware to perform memory management, task scheduling, and file management. Technically, the kernel is the OS. Shells Textual command line shells. Processes user requests - commands are translated by the shell into something the kernel can understand.

Shells OSX, and many versions of Linux use the Bash shell as its default - the Bourne Again Shell. Many different types of shells: C shell (csh), Bourne shell (sh), Korn shell (ksh) System utilities Commands such as ls, cp, grep, awk, sed, bc, wc Can be combined together to solve problems.

Unix file system Organized in a tree structure. Unix file system Unix file systems have directories and files. Unix is CASE sensitive. This means Vader, vader, VADER, vader are all different.

Types of files Plaintext - files in human-readable format. e.g. readme.txt Binary - files in machine-code. For example executables (a.out),.zips,.pdfs,.jpgs Commands A Unix command line consists of the name of a Unix command, followed by its "arguments" (options and the target filenames and/or expressions). The general syntax for a UNIX command is: $ command -options targets

ls ls is used to list files in a directory. By itself it just lists the file names, in alphabetical order. The command ls -la will list information associated with each file. ls a directory owner group date and time last modified $ ls -la total 72 drwxr-xr-x 9 mwirth staff 306 1 Sep 11:25. drwxr-xr-x@ 272 mwirth staff 9248 1 Sep 11:04.. -rwxr-xr-x 1 mwirth staff 9640 1 Sep 10:06 a.out -rw-r--r--@ 1 mwirth staff 3094 3 Jul 18:48 gamepig.c -rwxrwxrwx@ 1 mwirth staff 1439 30 Jun 10:02 luhn.c -rw-r--r--@ 1 mwirth staff 1717 3 Jul 12:01 mugwump.c -rw-r--r--@ 1 mwirth staff 490 31 Aug 08:04 paragraph.txt -rw-r--r-- 1 mwirth staff 473 31 Aug 08:36 paragraph2.txt -rw-r--r--@ 1 mwirth staff 3778 3 Jul 10:06 scramble.c $ permissions no. bytes file name

ls current directory $ ls -la total 72 drwxr-xr-x 9 mwirth staff 306 1 Sep 11:25. drwxr-xr-x@ 272 mwirth staff 9248 1 Sep 11:04.. -rwxr-xr-x 1 mwirth staff 9640 1 Sep 10:06 a.out -rw-r--r--@ 1 mwirth staff 3094 3 Jul 18:48 gamepig.c -rwxrwxrwx@ 1 mwirth staff 1439 30 Jun 10:02 luhn.c -rw-r--r--@ 1 mwirth staff 1717 3 Jul 12:01 mugwump.c parent directory -rw-r--r--@ 1 mwirth staff 490 31 Aug 08:04 paragraph.txt -rw-r--r-- 1 mwirth staff 473 31 Aug 08:36 paragraph2.txt -rw-r--r--@ 1 mwirth staff 3778 3 Jul 10:06 scramble.c $ pwd pwd is a command used to tell you which directory you are currently in.

cd cd is used to change directories. The general form of the cd command is as follows: cd directory-name pwd & cd current directory $ pwd /Users/mwirth/codingC $ cd afall15 change directory to afall15 $ ls a.out!! luhn.c!! paragraph.txt! scramble.c gamepig.c! mugwump.c! paragraph2.txt $ cd.. $ change directory to the parent (codingc)

cp cp is used to make copies of files. The general form of the cp command is as follows: cp srcfile destfile cp cp can also be used to put a copy of a file into a directory. The general form of this cp command is as follows: cp srcfile destdir

cp To copy the file a1mug.c to a1mugbackup.c : cp a1mug.c a1mugbackup.c To copy the file a1mug.c to a directory named a1backups : cp a1mug.c a1backups mv mv is used to rename files. The general form of the mv command is as follows: mv srcfile destfile

mv mv can also be used to move a file into a directory (this does not make a copy). The general form of this mv command is as follows: mv srcfile destdir cp To rename the file a1mug.c to a1mug.old : mv a1mug.c a1mug.old To move the file a1mug.c to a directory named deathstarplans : mv a1mug.c deathstarplans

rm rm is used to delete files. The general form of the rm command is as follows: rm filename rm CAREFUL!! rm is forever.

Other commands mkdir - make a directory rmdir - remove a directory touch - create an empty file, or modify a files timestamp cat - concatenate files, and print to screen more - similar to cat, but displays one screen at a time. grep The grep command searches for lines matching a specific pattern. The general form of the grep command is as follows: grep pattern files

grep $ grep main *.c gamepig.c:int main(void) luhn.c: // Return the remainder when divided by 10 luhn.c:int main(void) mugwump.c:int main(void) scramble.c:int main(void) $ find The find utility is used to search for files in a directory hierarchy. The general form of the find command is as follows: find path conditions

find $ find. -name mugwump.c./mugwump.c $ history All shells store a list of the commands that have been issued. The command history allows you to see this list.

history Commands in the list can be accessed and reexecuted using a single exclamation mark,!, which is often referred to as Bang. You can do! followed by a history number, or! followed by the first few characters of the command. history $ history 503 cd afall15/ 504 ls 505 gcc scramble.c 506./a.out $ $!505 gcc scramble.c $ $!g gcc scramble.c $

Redirecting output stdout mean the standard standard output (screen). It is also possible to redirect this using the operator >. Redirecting output $ ls a.out!! luhn.c!! paragraph.txt! scramble.c gamepig.c! mugwump.c! paragraph2.txt $ $ ls > flist $ Instead of outputting to the screen this redirects it to a file named flist.

Pipes The pipe creates a channel from one command to another. Pipes are created using the. The general form of a pipe is as follows: command1 command2 $ history grep cd 352 cd PRAC_inprog/ 383 cd codingc 501 cd codingc 503 cd afall15/ 545 cd.. 568 history grep cd $ Pipes Run the history command, then pipe the results into grep which will return all lines which contain the search term cd.

Processes Everything that runs in an OS has a process. A process is an instance of a running program. The ps (process snapshot) command tells you about your processes. $ ps PID TTY TIME CMD 9878 ttys000 0:00.32 -bash 11641 ttys001 0:00.02 -bash Processes Every process has a PID, or Process-ID, which identifies it. You can have a program running more than once... each will have their own PID. $ ps PID TTY TIME CMD 9878 ttys000 0:00.32 -bash 11641 ttys001 0:00.02 -bash

Processes To see everything running in the background, you can use ps -A $ ps -A PID TTY TIME CMD 1?? 2:51.39 /sbin/launchd 11?? 0:05.62 /usr/libexec/usereventagent 12?? 0:09.27 /usr/libexec/kextd When things go wonky... If a program runs for too long... maybe because it has gone into an infinite loop or something, it can be stopped by using:

When things go wonky... Sometimes a program will get stuck for some reason. It just stops responding. When this happens it s time to kill the process. $ ps PID TTY TIME CMD 9878 ttys000 0:00.35 -bash 11769 ttys000 0:00.12./a.out 11641 ttys001 0:00.02 -bash $ kill -9 11769 $ Need more info? Use man. Short for manual page. The general form of a man page is as follows: man command-name

Unix is all powerful You can write programs in shell languages, to perform processing that is easier than using a GUI. For example: #!/bin/bash for img in *.jpg do filename=$(basename "$img") extension="${filename##*.}" filename="${filename%.*}" echo $filename convert "$img" "$filename.png" done Shell scripting Use the bash shell Select all files ending in.jpg #!/bin/bash for img in *.jpg do filename=$(basename "$img") extension="${filename##*.}" } filename="${filename%.*}" echo $filename convert "$img" "$filename.png" done extract file name with no extension Convert the file to.png

Black holes Unix has an built-in black hole called /dev/null Any user can write to it. Anything written to it just disappears.