Introduction to UNIX. 2 Multitasking zForeground yCurrent Task yThe Command Running at the `$` Prompt zBackground yCommand Running Behind the Scenes yNot.

Slides:



Advertisements
Similar presentations
Welcome to Unix. Redistribution The authors (nor anyone else) provides no warranty or claim of accuracy of this document. Use at your own risk. You may.
Advertisements

Shell Script Assignment 1.
Introduction to UNIX Cornell University CS 316 – Fall 2006 Slides by Michael Siegenthaler.
Unix. Outline Commands Environment Variables Basic Commands CommandMeaning lslist files and directories ls -alist all files and directories mkdirmake.
1 Introduction to UNIX Ke Liu
©Colin Jamison 2004 Introduction to Linux Colin Jamison.
Chapter Seven Unix Shell Environments1 System Programming UNIX Shell Environments.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
UNIX Chapter 00 A “ Quick Start ” into UNIX Operating System Mr. Mohammad Smirat.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Introduction to Linux Workshop February Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
June 1, 1999Using The C-Shell1 Introduction to UNIX F. Using C Shell Features.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Introduction to Computer Organization & Systems Topics: Intro to UNIX COMP John Barr.
CS 2061 Shells Also known as: Unix Command Interpreter.
Shells. A program that is an interface between a user at a terminal and the computers resouces ▫The terminal may be real or an emulator The shell is.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Introduction to Linux Azzam Mourad COEN 346.
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 OS (IV) AUBG ICoSCIS Team Prof. Volin Karagiozov March, 09 – 10, 2013 SWU, Blagoevgrad.
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.
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.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
L&T Infotech1 UNIX – Getting Started - Aneesh Ramani.
Introduction to UNIX. 2 Unix File System zDirectory Organization zHierarchy of Files & Directories.
UNIX shell environments CS 2204 Class meeting 6 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
User Environments Objectives –to provide appropriate environments for different types of users Contents –different login programs –user profiles –restricted.
Lab 3 + Using the Terminal 1. "Under Linux there are GUIs (graphical user interfaces). where you can point and click and drag, and hopefully get work.
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Introduction to Programming Using C An Introduction to Operating Systems.
Customizing the Shell Environment. UNIX Shells Two characteristics of shells –Interactive: prompts ($) and waits for your response/requests –Noninteractive:
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.
Linux Commands C151 Multi-User Operating Systems.
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
Introduction to Linux Workshop February 15, 2016.
Laboratory 1.2a1 First steps with Unix - Lab Boris Steipe Department of Biochemistry Department.
Shells.
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.
Getting started with CentOS Linux
Introduction to Shells
Writing Shell Scripts ─ part 1
Andy Wang Object Oriented Programming in C++ COP 3330
Shell Script Assignment 1.
Basic UNIX OLC Training.
LING 408/508: Computational Techniques for Linguists
John Carelli, Instructor Kutztown University
Unix : Introduction and Commands
Introduction to Computer Organization & Systems
UNIX Commands A Brief Look at Common UNIX Commands.
Writing Shell Scripts ─ part 1
Getting started with CentOS Linux
Andy Wang Object Oriented Programming in C++ COP 3330
UNIX Commands A Brief Look at Common UNIX Commands.
Linux Shell Script Programming
Writing Shell Scripts ─ part 1
UNIX Commands A Brief Look at Common UNIX Commands.
CSE 303 Concepts and Tools for Software Development
Chapter 3 The UNIX Shells
Presentation transcript:

Introduction to UNIX

2 Multitasking zForeground yCurrent Task yThe Command Running at the `$` Prompt zBackground yCommand Running Behind the Scenes yNot Interactive (e.g. text editor)

3 Multitasking zBackground Tasks y&Perform Command in the Background $ who > whoson & [1] $ $ who > whoson & [1] $ zImportant Notes yLogoff Terminates Background Tasks yDo Not Overload The System yCan Not Require Keyboard Input yScreen Output May Not Be Desirable

4 Multitasking zBackground Tasks ynohup UnixCommand xPrevents Command From Terminating on Logoff $ nohup who & nohup: appending output to 'nohup.out' $ $ nohup who & nohup: appending output to 'nohup.out' $ $ nohup who > whoson & $ $ nohup who > whoson & $ No output file specified. Output redirected to nohup.out Output redirected to whoson

5 Multitasking zEvery Command is Assigned a Unique Number zProcess ID (PID) zpsDisplay Currently Running Tasks $ who > whoson;sleep 15 & $ $ who > whoson;sleep 15 & $ $ ps PID TTY STAT TIME COMMAND p1 S 0:00 login -h p1 S 0:00 -sh p1 S 0:00 sleep p1 R 0:00 ps $ $ ps PID TTY STAT TIME COMMAND p1 S 0:00 login -h p1 S 0:00 -sh p1 S 0:00 sleep p1 R 0:00 ps $

6 Multitasking zps [-aux] yDisplay Currently Running Processes (Tasks) y-a All User Processes y-u User Info y-x Not Attached to a Terminal $ ps -aux USER PID %CPU %MEM SIZE RSS TTY STAT START TIME COMMAND bin ? SW Sep 9 0:00 (portmap) nobody ? S Sep 16 0:00 httpd nobody ? S Sep 16 0:00 httpd jsmith p0 S 21:21 0:00 login -h jsmith p0 S 21:21 0:00 -sh rdefe p1 S 21:36 0:00 login -h rdefe p1 S 21:36 0:00 -sh rdefe p1 R 21:47 0:00 ps aux root ? S Sep 9 0:33 init [3] $ ps -aux USER PID %CPU %MEM SIZE RSS TTY STAT START TIME COMMAND bin ? SW Sep 9 0:00 (portmap) nobody ? S Sep 16 0:00 httpd nobody ? S Sep 16 0:00 httpd jsmith p0 S 21:21 0:00 login -h jsmith p0 S 21:21 0:00 -sh rdefe p1 S 21:36 0:00 login -h rdefe p1 S 21:36 0:00 -sh rdefe p1 R 21:47 0:00 ps aux root ? S Sep 9 0:33 init [3]

7 Multitasking zkill [-9] PID 1 PID 2 … PID N yStop (kill) A Currently Running Process yCan Only Stop Your Processes y-9 `Sure Kill` $ kill $ $ kill $ $ ps PID TTY STAT TIME COMMAND p1 S 0:00 login -h p1 S 0:00 -sh p1 S 0:00 report p1 R 0:00 ps $ $ ps PID TTY STAT TIME COMMAND p1 S 0:00 login -h p1 S 0:00 -sh p1 S 0:00 report p1 R 0:00 ps $ $ kill $ $ kill $ $ kill 0 $ $ kill 0 $

8 Multitasking zjobsList background jobs zkill %1Kill background job 1 $ jobs [1] Running prog1 & [2]- Running report23 & [3]+ Running x57 & $ kill %2 [2]- Terminated report23 $ $ jobs [1] Running prog1 & [2]- Running report23 & [3]+ Running x57 & $ kill %2 [2]- Terminated report23 $

9 Command Line Editing zCommand History $ history ls -l data 654 pwd 655 vi junk 656 pwd 657 ls data 658 cat data/junk 659 cat junk 660 who 661 ls | grep m $ $ history ls -l data 654 pwd 655 vi junk 656 pwd 657 ls data 658 cat data/junk 659 cat junk 660 who 661 ls | grep m $ Display the last 9 commands

10 Command Line Editing zEditing Commands on the command line ySetting command editor to vi yCommands can be changed using vi editing commands $ set –o vi $ history cat junk 660 who 661 ls | grep m $ ls | grep m $ set –o vi $ history cat junk 660 who 661 ls | grep m $ ls | grep m Press ESC – to return last command

11 Command Line Editing zEditing commands using fc $ history ls -l data 654 pwd 655 vi p1 $ fc 656 $ $ fc –s 660 $ history ls -l data 654 pwd 655 vi p1 $ fc 656 $ $ fc –s 660 Edit command using vi. Command is run when you exit vi. Run command 660

12 Command Aliases zDefine Command Preferences zRedefine or create new or compound commands $ alias ls=“ls –p” $ alias cp=“cp –i” $ alias alias ls=‘ls –p’ alias cp=‘cp –i’ $ ls a999 et mail/ mymail xyz bin/ examples-cpio mbox public_html/ $ alias ls=“ls –p” $ alias cp=“cp –i” $ alias alias ls=‘ls –p’ alias cp=‘cp –i’ $ ls a999 et mail/ mymail xyz bin/ examples-cpio mbox public_html/

13 Command Aliases zDisabling Aliases $ alias alias ls='ls -p‘ $ $ ls a999 et/ mail/ mymail $ $ alias alias ls='ls -p‘ $ $ ls a999 et/ mail/ mymail $ $ \ls a999 et mail mymail $ $ \ls a999 et mail mymail $ $ unalias ls $ $ unalias ls $

14 Shell Scripts zText File Containing Unix Commands zMust Use Correct Commands & Syntax yOptions, Arguments, One Command per Line, etc. $ cat ll ls -l $ sh ll -rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 feb -rw-r--r-- 1 rdefe unix 62 Sep 12 21:47 ll $ $ cat ll ls -l $ sh ll -rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 feb -rw-r--r-- 1 rdefe unix 62 Sep 12 21:47 ll $ $ chmod u+x ll $ ll -rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 feb -rwxr--r-- 1 rdefe unix 62 Sep 12 21:47 ll $ $ chmod u+x ll $ ll -rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 feb -rwxr--r-- 1 rdefe unix 62 Sep 12 21:47 ll $

15 Shell Scripts zecho [String] yDisplay a Message to the Screen $ cat ll echo “my ls command” ls -l $ ll my ls command -rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 feb -rwxr--r-- 1 rdefe unix 62 Sep 12 21:47 ll $ $ cat ll echo “my ls command” ls -l $ ll my ls command -rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 feb -rwxr--r-- 1 rdefe unix 62 Sep 12 21:47 ll $

16 Shell Scripts zPassing Arguments to Shell Scripts yPositional Parameters $ cat ll ls -l $ ll data $ cat ll ls -l $ ll data List the contents of a directory? No! $ cat ll ls -l $1 $ ll data $ cat ll ls -l $1 $ ll data List the contents of a directory? Yes!

17 Shell Scripts zPassing Arguments to Shell Scripts yPositional Parameters $ cat ll ls -l $1 $2 $3 $ $ cat ll ls -l $1 $2 $3 $ $ ll data mail docs $0 Script File Name $1 - $9 Arguments 1-9 $* All Arguments $0

18 Shell Scripts zPositional Parameters yUse Any Where, Any Place for Any Purpose $ cat mymove mv $1 $1.new $ $ cat mymove mv $1 $1.new $ $0 Script File Name $1 - $9 Arguments 1-9 $* All Arguments $ cat mymore pr -n $* | more $ $ cat mymore pr -n $* | more $ $ cat mylog date >> log who >> log grep $1 log $ $ cat mylog date >> log who >> log grep $1 log $

19 Shell Scripts zExamples $ cat param echo "the number of parameters passed = $#" echo "param 0 = $0" echo "param 1 = $1" echo "param 2 = $2" echo "param 3 = $3" echo "param * = $*" $ $ cat param echo "the number of parameters passed = $#" echo "param 0 = $0" echo "param 1 = $1" echo "param 2 = $2" echo "param 3 = $3" echo "param * = $*" $ $ param aaa bbb ccc the number of parameters passed = 3 param 0 =./param param 1 = aaa param 2 = bbb param 3 = ccc param * = aaa bbb ccc $ param aaa bbb ccc the number of parameters passed = 3 param 0 =./param param 1 = aaa param 2 = bbb param 3 = ccc param * = aaa bbb ccc

20 Unix File Permissions zDetermines Who Can Access What File $ ls -l -rwxrw-r-- 1 rdefe unix 53 Sep 12 21:46 p1 -rwxr-xr-x 1 rdefe unix 62 Sep 12 21:47 mar $ $ ls -l -rwxrw-r-- 1 rdefe unix 53 Sep 12 21:46 p1 -rwxr-xr-x 1 rdefe unix 62 Sep 12 21:47 mar $ rRead Permission wWrite Permission xExecute Permission -Place Holder/No Permission

21 Unix File Permissions $ ls -l -rwxrw-r-- 1 rdefe unix 53 Sep 12 21:46 p1 -rwxr-xr-x 1 rdefe unix 62 Sep 12 21:47 mar $ $ ls -l -rwxrw-r-- 1 rdefe unix 53 Sep 12 21:46 p1 -rwxr-xr-x 1 rdefe unix 62 Sep 12 21:47 mar $ OwnerGroup zOwner zGroup zOther OwnerGroupOther

22 Unix File Permissions $ ls -l -rw-rw-r-- 1 rdefe unix 53 Sep 12 21:46 p1 $ chmod gu+x p1 $ ls -l -rwxrwxr-- 1 rdefe unix 53 Sep 12 21:46 p1 $ ls -l -rw-rw-r-- 1 rdefe unix 53 Sep 12 21:46 p1 $ chmod gu+x p1 $ ls -l -rwxrwxr-- 1 rdefe unix 53 Sep 12 21:46 p1 zchmod [u|g|o|a] [+|-|=] [r|w|x] File 1 File 2 … File N y+ Add Permission Note: You can only change permissions on files that you own.

23 Unix File Permissions $ ls -l -rwxrwxr-x 1 rdefe unix 53 Sep 12 21:46 p1 $ chmod g-w,-x p1 $ ls -l -rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 p1 $ ls -l -rwxrwxr-x 1 rdefe unix 53 Sep 12 21:46 p1 $ chmod g-w,-x p1 $ ls -l -rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 p1 zchmod [u|g|o|a] [+|-|=] [r|w|x] File 1 File 2 … File N y- Remove Permission

24 Unix File Permissions $ ls -l -rwxrw-r-- 1 rdefe unix 53 Sep 12 21:46 p1 $ chmod u=r,g=rx p1 $ ls -l -r--r-xr-- 1 rdefe unix 53 Sep 12 21:46 p1 $ ls -l -rwxrw-r-- 1 rdefe unix 53 Sep 12 21:46 p1 $ chmod u=r,g=rx p1 $ ls -l -r--r-xr-- 1 rdefe unix 53 Sep 12 21:46 p1 zchmod [u|g|o|a] [+|-|=] [r|w|x] File 1 File 2 … File N y= Set to a specific value

25 Shell Variables zStore Values & Text Information zValues Are Lost When You Logoff $ x=678 $ echo $x 678 $ mesg=“This is a text string” $ echo $mesg This is a text string $ x=678 $ echo $x 678 $ mesg=“This is a text string” $ echo $mesg This is a text string

26 Shell Variables zEnvironmental Variables zStores Important Setup Information $ env PS1=$ PATH=/usr/local/bin:/bin:/usr/bin:/usr/bin/mh HOSTNAME=unix.ccri.cc.ri.us USER=rdefe MAIL=/var/spool/mail/rdefe HOME=/home/rdefe TERM=vt220 LOGNAME=rdefe $ $ env PS1=$ PATH=/usr/local/bin:/bin:/usr/bin:/usr/bin/mh HOSTNAME=unix.ccri.cc.ri.us USER=rdefe MAIL=/var/spool/mail/rdefe HOME=/home/rdefe TERM=vt220 LOGNAME=rdefe $

27 Shell Variables zChanging Environmental Variables yPS1 $ echo $PS1 $ $ export PS1='> ' > > export PS1='$PWD> ' /home/rdefe> cd /etc /etc> cd /home/rdefe> /home/rdefe> export PS1='$ ' $ $ echo $PS1 $ $ export PS1='> ' > > export PS1='$PWD> ' /home/rdefe> cd /etc /etc> cd /home/rdefe> /home/rdefe> export PS1='$ ' $

28 Shell Variables zChanging Environmental Variables yPATH $ echo $PATH /usr/local/bin:/bin:/usr/bin:. $ export PATH=$PATH:$HOME/bin $ echo $PATH /usr/local/bin:/bin:/usr/bin:.:/home/rdefe/bin $ $ echo $PATH /usr/local/bin:/bin:/usr/bin:. $ export PATH=$PATH:$HOME/bin $ echo $PATH /usr/local/bin:/bin:/usr/bin:.:/home/rdefe/bin $

29 Shell Variables zSaving Environmental Changes z.bash_profile xShell Script Run at Login Time xJust Like Any Shell Script $ cat.bash_profile mesg n export PATH=$PATH:$HOME/bin export PS1='$PWD> ' who -q $ $ cat.bash_profile mesg n export PATH=$PATH:$HOME/bin export PS1='$PWD> ' who -q $

30 Shell Variables zUsing Shell Variables in Shell Scripts $ cat mycopy end=123 cp $1 $HOME/$1.$end $ $ mycopy mbox $ cat mycopy end=123 cp $1 $HOME/$1.$end $ $ mycopy mbox Creates the file mbox.123 in your home directory