Introduction to UNIX CSE 2031 Fall 2010 14 May 2015.

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
A Practical Guide to Fedora and Red Hat Enterprise Linux Unit 4: More Command Line Interface (CLI) Chapter 7: The Linux Shell By Fred R. McClurg Linux.
1 Introduction to UNIX Ke Liu
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
1 UNIX essentials (hands-on) the directory tree running programs the shell (using the T-shell) → command line processing → special characters → command.
Linux Commands LINUX COMMANDS.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Systems Programming Concepts
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
3 File Processing Mauro Jaskelioff. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Unix Basics Chapter 4.
Advanced UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Unix Shells Based on Glass & Abels’ Book CS240 Computer Science II.
Introduction to Computer Organization & Systems Topics: Intro to UNIX COMP John Barr.
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
Dedan Githae, BecA-ILRI Hub Introduction to Linux / UNIX OS MARI eBioKit Workshop; Nov , 2014.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
1 UNIX essentials (hands-on) the directory tree running programs the shell → command line processing → special characters → command types → shell variables.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
INTRODUCTION TO LINUX Jacob Chan. GNU/Linux Consists of Linux kernel, GNU utilities, and open source and commercial applications Works like Unix –Multi-user.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
Lesson 2 1.Commands 2.Filename Substitution 3.I/O Redirection 4.Command Grouping 5.Shell Responisibilites Review of the Basics.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
Chapter Four I/O Redirection1 System Programming Shell Operators.
Getting Started UNIX InKwan Yu Topics Unix Commands Unix System calls C function calls.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
Linux Commands C151 Multi-User Operating Systems.
Files and Directories in UNIX The first file in UNIX file system is “root” or “/”
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
Introduction to UNIX (part 2) CSE 2031 Fall March 2016.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Learning Unix/Linux Based on slides from: Eric Bishop.
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Tutorial of Unix Command & shell scriptS 5027
Chapter 11 Command-Line Master Class
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Some Linux Commands.
C151 Multi-User Operating Systems
CSE 374 Programming Concepts & Tools
Tutorial of Unix Command & shell scriptS 5027
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
Introduction to Linux Week 0 - Thursday.
Tutorial of Unix Command & shell scriptS 5027
Introduction to Computer Organization & Systems
UNIX Reference Sheets CSE 2031 Fall 2010.
Tutorial Unix Command & Makefile CIS 5027
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Chapter 3 The UNIX Shells
Introduction to UNIX (part 2)
Introduction to UNIX (part 2)
Introduction to UNIX (part 2)
Introduction to UNIX EECS July 2019.
LPI Linux Certification
Presentation transcript:

Introduction to UNIX CSE 2031 Fall May 2015

Introduction UNIX is an operating system (OS). Our goals:  Learn how to use UNIX OS.  Use UNIX tools for developing programs/software, specifically shell programming. 2

Processes Each running program on a UNIX system is called a process. Processes are identified by a number (process id or PID). Each process has a unique PID. There are usually several processes running concurrently in a UNIX system. 3

ps command % ps a# list all processes 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 pts/24 00:00:00 sleep pts/93 00:00:00 ps pts/90 00:00:00 vim pts/24 00:00:07 stayAlive pts/44 00:00:01 xterm... 4

The File System Directory structure Current working directory Path names Special notations 5

Directory Structure 6

Current Working Directory Every process has a current working directory. In a shell, the command ls shows the contents of the current working directory. pwd shows the current working directory. 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

Special Characters. means the current directory.. means the parent directory  cd..  cd../Notes ~ means the home directory  cat ~/lab3.c To go directly to your home directory, type  cd 9

Frequently Used Terminal Keystrokes Interrupt the current process: Ctrl-C End of file: Ctrl-D Read input (stdin) from a file o a.out < input_file Redirect output (stdout) to a file o ls > all_files.txt # overwrites all_files.txt Append stdout to a file o ls >> all_files.txt# append new text to file

Wildcards (File Name Substitution) Goal: referring to several files in one go. ?match single character  ls ~/C2031/lab5.???  lab5.doc lab5.pdf lab5.out *match any number of characters  ls ~/C2031/lab5.* […] match any character in the list enclosed by [ ]  ls ~/C2031/lab[567].c  lab5.c lab6.c lab7.c 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

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 Get on-line help with man man chgrp Some commonly used commands cat, more who grep echo date sort wc ps, kill history 14

cat, more, tail % cat phone_book Yvonne Amy William John Annie % 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 % tail +3 myfile.txt Display the file starting from the 3 rd line. 15

echo 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. It is not necessary to surround the strings with quotes, as it does not affect what is written on the screen. If quotes (either single or double) are used, they are not repeated on the screen. % echo ‘This is’”a test.” This is a test. To display single/double quotes, use \’ or \” 16

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 string 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

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 enum.c % wc [e]*.c enum.c ex1.c ex2.c total % wc -c enum.c 220 enum.c % wc -w enum.c 37 enum.c % wc -l enum.c 14 enum.c 20

sort % cat phone_book Yvonne Amy William John Annie % sort phone_book Amy Annie John William Yvonne Try these options: sort –r reverse normal order sort –n numeric order sort –nr reverse numeric order sort –f case insensitive 21

cmp, diff % cat phone_book Yvonne Amy William John Annie % cat phone_book2 Yvonne Amy William John Annie % cmp phone_book phone_book2 phone_book phone_book2 differ: char 30, line 2 % diff phone_book phone_book2 2c2 < Amy > Amy c4 < John > John

who % who ossama pts/13 Nov 7 00:22 (ip dynamic.yorku.ca) hoda pts/21 Nov 4 16:49 (gomez.cs.yorku.ca) gordon pts/24 Nov 5 10:40 (bas2-toronto 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-toronto dsl.bell.ca) User name Terminal associated with the process 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 pts/24 00:00:00 sleep pts/43 00:00:00 sleep pts/93 00:00:00 ps pts/90 00:00:00 vim pts/44 00:00:01 xterm... % kill is the KILL signal 24

history % history :45 ls :47 cd Demo_2031/ :48 ls :48 m ex1.c :49 who :50 history :52 ls -a :56 ls Stack/ :57 ls :57 history 10 25

Pipes Pipe: a way to connect the output of one program to the input of another program without any temporary file. Pipeline: connection of two or more programs through pipes. Examples: ls –l | wc –l # 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

NEVER-DO List in UNIX 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. Avoid using * with rm such as rm *, rm *.c 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. Do not name an executable file test.  There is a Unix command called test. 27

Next time … Writing Shell Scripts Reading: Chapters 1 and 2 “Practical Programming in the UNIX Environment” 28