The UNIX Shell Software Tools. Slide 2 Basic Shell Syntax command [-[options]] [arg] [arg] … l The name of the command is first l Options are normally.

Slides:



Advertisements
Similar presentations
More Shell Programming Software Tools. Slide 2 Keyword Shell Variables l The shell sets keyword shell variables. You can use (and change) them. HOME The.
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.
Introduction to UNIX CSE 2031 Fall May 2015.
Processes and Job Control. Foreground and Background (1)  Unix is a multi-tasking operating system –some of these tasks are being done by other users.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
LINUX System : Lecture 3 (English-Only Lecture) Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University Acknowledgement.
1 Introduction to UNIX Ke Liu
1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Perl Process Management Software Tools. Slide 2 system Perl programs can execute shell commands (Bourne shell) using the system function. system("date");
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
Shell Programming Software Tools. Slide 2 Shells l A shell can be used in one of two ways: n A command interpreter, used interactively n A programming.
Perl Process Management Learning Objectives: 1. To learn the different Perl’s commands for invoking system process 2. To learn how to perform process management.
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.
UNIX Utilities Software Tools. Slide 2 Getting Started on UNIX The machines in CS Lab2 are named csl2wk01 through csl2wk41. csl2wk01 means “CSLab2, workstation#1”
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.
Shell Programming Learning Objectives: 1. To understand the some basic utilities of UNIX File 2. To compare UNIX shell and popular shell 3. To learn the.
UNIX Utilities Learning Objectives: 1. To understand the some basic utilities of UNIX File 2. To compare UNIX shell and popular shell 3. To learn Input/Output.
1 UNIX essentials (hands-on) the directory tree running programs the shell (using the T-shell) → command line processing → special characters → command.
Introduction to Linux and Shell Scripting Jacob Chan.
Shell Programming. Shell Scripts (1) u Basically, a shell script is a text file with Unix commands in it. u Shell scripts usually begin with a #! and.
Shell Script Examples.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
An Introduction to UNIX System --- Cosc513 Presentation n Instructor: Morteza Anvari n Author: Yonghong Pan n ID#: n Date: Jan.29, 2001.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 8 Shell.
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.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
CS 6560 Operating System Design Lecture 3:Tour of GNU/Linux.
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.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Introduction to Linux OS (IV) AUBG ICoSCIS Team Prof. Volin Karagiozov March, 09 – 10, 2013 SWU, Blagoevgrad.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
CS465 - UNIX The Bourne Shell.
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 Operating Systems Lecture 2 UNIX and Shell Scripts.
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.
Shell Programming. The UNIX Shell  The UNIX shell listens to what you type and executes commands at your request. User command: lpr file UNIX Shell UNIX.
Shell Programming Learning Objectives: 1. To understand the some basic utilities of UNIX File 2. To compare UNIX shell and popular shell 3. To learn the.
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.
Chapter 5: The Shell The Man in the Middle. In this chapter … The command line Input, output, and redirection Process management Wildcards and expansion.
More Shell Programming. Slide 2 Control Flow  The shell allows several control flow statements:  if  while  for.
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Introduction to Shells
Shell Features CSCI N321 – System and Network Administration
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
The UNIX Shell Learning Objectives:
System Programming and administration CS 308
Part 1: Basic Commands/Utilities
Some Linux Commands.
CSE 303 Concepts and Tools for Software Development
Basic UNIX OLC Training.
An Introduction to UNIX System --- Cosc513 Presentation
Linux Shell Script Programming
Shell Programming.
CSE 303 Concepts and Tools for Software Development
Chapter 3 The UNIX Shells
Presentation transcript:

The UNIX Shell Software Tools

Slide 2 Basic Shell Syntax command [-[options]] [arg] [arg] … l The name of the command is first l Options are normally single letters that turn an option on or off. They can be combined or given separately. $ ls -dil $ ls -l -d -i l Options sometimes also take a value. The value can usually be either given right after the option or separately: $ ypcat -d ug.cs.ust.hk passwd

Slide 3 Command Options l Most commands require you to give all options before filename arguments. The following command works in Linux, but not SunOS: $ cat names -n George W. Bush Bill Gates Bill Clinton George W. Bush cat: cannot open –n l Spaces separate options. To turn something with spaces into a single argument, use quotes: $ grep vote thing letter1 grep: can’t open thing letter1:You have the Florida vote thing $ grep ”vote thing” letter1 You have the Florida vote thing

Slide 4 Command Options l Double quotes and single quotes are a bit different. For now, you can use them interchangeably. $ grep ‘vote thing’ letter1 You have the Florida vote thing l To escape a single character (prevent it from being treated specially) proceed it with a backslash: $ grep ”We\’ll” letter2 by my office. We'll tidy up a few more things before $ echo ”*” * $ echo ‘*’ * $ echo \* * $ echo * letter1 letter2 names secret/

Slide 5 How Does the Shell Find a Command ? l The shell searches a list of directories for an executable file with the same name. l The list of directories is stored in the PATH variable for Bourne shells and in the path array for csh/tcsh $ PATH=/usr/local/bin:$PATHsh % set path=(/usr/local/bin $path)csh, tcsh l If there is a match in more than one directory, the shell uses the first one it finds. l If you want to run a command that is not in one of these directories, you can give a pathname (relative or absolute) instead. ~horner/bin/csound

Slide 6 How Does the Shell Find a Command ? l A few commands are built into the shell. This varies from shell to shell. The echo command, for example, is often builtin, for efficiency. You can find out where the shell is getting a particular command using the “ which ” command in any shell: $ which echo echo: shell built-in command. $ which cat /bin/cat $ which grep /bin/grep $ which ls ls: aliased to ls --color=tty Makes directories blue, executables green, and soft links aqua

Slide 7 Alias The C Shell has the alias command, which allows you to create command shortcuts. $ alias ls "ls -F" $ alias rm "rm -i" $ alias + "chmod u+x *" $ alias - "chmod u-x *" $ alias 111 "cd ~horner/111" $ pwd /bin $ 111 $ pwd /homes/horner/111 On most Unix machines (except Mandriva/Mandrake in CSLab2), if you put the alias commands in your.cshrc file, you can use them every time you login.

Slide 8 Standard Input l Every time you login, or run a shell, you are “connected” to the computer on a particular terminal. $ who horner pts/3 Feb 14 10:23 (csnt1.cs.ust.hk) horner pts/0 Feb 14 11:57 (csz096.cs.ust.hk) These devices ( pts/0 ) are actually files in the directory /dev. So, if you are logged in on pts/0, this works just fine: $ date > /dev/pts/0 Mon Feb 14 17:08:21 HKT 2005

Slide 9 Standard Input In fact, you can redirect stdout to a different device (e.g., pts/3 ), if you have permission. (The write command works this way.) You can find out which terminal a particular shell is connected to using the tty command: $ tty /dev/pts/0 $ echo " Hi Andrew! " > /dev/pts/3 $

Slide 10 Tee l A special command called tee acts like a T-joint in plumbing: $ who horner pts/3 Feb 14 10:23 (csnt1.cs.ust.hk) horner pts/0 Feb 14 11:57 (csz096.cs.ust.hk) $ who | sort | tee sortedwho | wc -l 2 $ cat sortedwho horner pts/0 Feb 14 11:57 (csz096.cs.ust.hk) horner pts/3 Feb 14 10:23 (csnt1.cs.ust.hk) $ In this example, the output of sort is placed in a file “ sortedwho “ and piped to wc -l, which counts the number of lines.

Slide 11 Background Jobs l A simple command or pipeline can be put into the background by following it with the “&” character: $ sort names > names.sort & [1] 3236 $ l The shell will print the process ID (PID), and a job number (1, in this case). l In some shells, you will be notified when the job is done (you may have to hit return again): $ sort names > names.sort & [1] 3236 $ [1] Done sort names > names.sort $

Slide 12 Background Jobs l Put a job in the background by typing “CTRL-Z” $ ypcat passwd | sort >passwd.sort ^Z Suspended $ The job is suspended - not running - until you either place it in the background using bg : $ bg [1] ypcat passwd | sort > passwd.sort & $ or back to the foreground using fg : $ fg ypcat passwd | sort >passwd.sort $

Slide 13 Jobs The jobs command tells you what jobs are running: $ ypcat passwd | sort > passwd.sort ^Z Suspended $ jobs [1] + Suspended ypcat passwd | sort > passwd.sort $ l You can stop a job with the kill command: $ ypcat passwd | sort > passwd.sort & [1] $ kill %1 $ [1]Terminatedypcat passwd | Exit 2sort > passwd.sort $ The “%1” means “job #1”. You can also use the PID.

Slide 14 Jobs l The ps command is the main way to find out about jobs: $ ps PID TTY TIME CMD 1401 pts/0 0:01 csh $ $ ypcat passwd | sort > passwd.sort & [1] $ ps PID TTY TIME CMD 3477 pts/0 0:00 sort 1401 pts/0 0:01 csh 3476 pts/0 0:01 ypcat $

Slide 15 Jobs l Note that if you put something into the background, you better redirect stdout, or the output will appear on your screen anyway! $ ypcat passwd & ma_wmkaa:uq2jXK0sFQ8Jg:36747:5000:Woo Man Kei,,=EXP =nc99S:/homes/ma_h ma_chyaa:CS9wq.1zOxnhI:35435:5000:Chu How Yin Agnes,,=EXP =nc98F:/homs ee_tkcaa:9LtI7Tipk2Ca6:35651:5000:Tsang Kong Chau,,=EXP =nc99S:/homesh eg_cck:yi7XtKxxP5KaQ:43555:10010:Cheung Chi Keung,,ce98_yr1:/homes/eg_cck:/bin/h cs_wks:dtjvwifI2G7v2:24514:10001:Wong Kin Shing,,cs98_yr1:/homes/cs_wks:/bin/tch cs_lwk:OWiGoJRXSjn.s:24032:10001:Leung Wai Kei Ricky,,cs98_yr2:/homes/cs_lwk:/bh ph_chyac:CSJUo9e2KGqKg:35955:5000:Chan Hoi Yan,,=EXP =nc98F:/homes/phs ee_wkkab:dfbi3GqWjvf5U:35644:5000:Wong Ka Keung,,=EXP =nc99S:/homes/eh ph_lcy:CSwGgr5IeIvqc:36689:5000:Lam Chi Yin,,=EXP =nc99S:/homes/ph_lcx ^C $ ypcat passwd >file & $

Slide 16 More Pattern Matching l The notation “[abcd]” matches any single one of the enclosed characters. $ ls [il]* it it1 ith letter1 letter4 $ l The notation “[a-z]” matches any lowercase letter. l The notation “[0-9]” matches any digit character. l The notation “[0-59]” matches any the digit characters 0, 1, 2, 3, 4, 5, and 9. $ ls letter* letter1 letter4 $ ls letter[0-35] letter1 $ ls letter[0-24] letter1 letter4

Slide 17 More Pattern Matching l Most shells allow you to give a list of strings in curly brackets, comma separated: $ ls *{1,.sort} NAMES1 it1 names.sort f1 letter1 passwd.sort secret1: secret1: Permission denied $

Slide 18 Switching Shells l You can switch shells by just typing its name: csl2wk01.cs.ust.hk> ps PID TTY TIME CMD 3496 pts/0 0:01 csh csl2wk01.cs.ust.hk> tcsh csl2wk01.cs.ust.hk> ps PID TTY TIME CMD 3650 pts/0 0:00 tcsh 3496 pts/0 0:01 csh csl2wk01.cs.ust.hk> sh $ ps PID TTY TIME CMD 3650 pts/0 0:00 tcsh 3496 pts/0 0:01 csh 3659 pts/0 0:00 sh $ ^D csl2wk01.cs.ust.hk> ps PID TTY TIME CMD 3650 pts/0 0:00 tcsh 3496 pts/0 0:01 csh

Slide 19 Combining Commands l Multiple pipelines can be input on one command line by separating them with semicolons. l When entering a long command, use a backslash (\) to continue the command on the next line. $ date; sort names; \ who Mon Feb 14 19:40:28 HKT 2005 Bill Clinton Bill Gates George W. Bush horner pts/3 Feb 14 10:23 (csnt1.cs.ust.hk) horner pts/0 Feb 14 19:11 (csz096.cs.ust.hk)

Slide 20 Combining Commands l Commands can be grouped together using parentheses l There are two main reasons to group commands: n To create a “single command” out of a group of commands (especially useful before a pipe): $ (cat letter1; head -2 names) | sort >list To run a set of commands in their own subshell (especially when trying to limit the effect of a cd command): $ (cd secret; ls | wc -l); ls | wc -l 3 25 This line has the effect of counting the files in secret, and then counting the files in the current directory.