CS 497C – Introduction to UNIX Lecture 4: Understanding the UNIX Command Chin-Chih Chang

Slides:



Advertisements
Similar presentations
RH030 Linux Computing Essentials
Advertisements

CS 497C – Introduction to UNIX Lecture 11: - The File System Chin-Chih Chang
The Unix File System. What are the three parts of every file on a Unix filesystem? And where is each stored? Filename - stored in directories Inode -
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
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.
Linux+ Guide to Linux Certification, Second Edition
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
UNIX chapter 04 UNIX Shells Mr. Mohammad Smirat. Introduction The shell is the software that listens to commands typed in at the terminal and translates.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
CS 497C – Introduction to UNIX Lecture 21: - The Shell Chin-Chih Chang
CS 497C – Introduction to UNIX Lecture 20: - The Shell Chin-Chih Chang
CS 497C – Introduction to UNIX Lecture 12: - The File System Chin-Chih Chang
CS 497C – Introduction to UNIX Lecture 27: - The Process Chin-Chih Chang
CS 497C – Introduction to UNIX Lecture 16: - File Attributes Chin-Chih Chang
Guide To UNIX Using Linux Third Edition
Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files.
CS 497C – Introduction to UNIX Lecture 13: - The File System Chin-Chih Chang
Using Linux Commands 2 Lab#5
2 $ command Command Line Options ls –a –l hello hi Command Arguments.
Using Linux Commands 2 Lab#5. Sort command Sort the lines of text files. $ sort fileName by default it will sort in normal order(alphabetical 0-9 A-Z.
CTEC 1863 – Operating Systems Shell Scripting. CTEC F2 Overview How shell works Command line parameters –Shift command Variables –Including.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell The agency that.
Unix Shells Based on Glass & Abels’ Book CS240 Computer Science II.
An Introduction to Unix Shell Scripting
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.
Shell Scripting Todd Kelley CST8207 – Todd Kelley1.
UNIX and Shell Programming (06CS36) Unit 1 Continued… Shrinivas R. Mangalwede Department of Computer Science and Engineering K.L.S. Gogte Institute of.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Linux+ Guide to Linux Certification, Third Edition
Linux Operations and Administration
Shell Programming Any command or a sequence of UNIX commands stored in a text file is called a shell program. It is common to call this file a command.
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.
LINUX programming 1. INDEX UNIT-III PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Problem solving approaches in Unix,Using.
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
Writing Scripts Hadi Otrok COEN 346.
Introduction to Programming Using C An Introduction to Operating Systems.
Manage Directories and Files in Linux Part 2. 2 Identify File Types in the Linux System The file types in Linux referred to as normal files and directories.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
THE BOURNE SHELL. Shell : the agency that sits between the user and the UNIX system. The BOURNE SHELL named after its founder Steve Bourne, is one of.
Compunet Corporation Introduction to Unix (CA263) Your Environment By Tariq Ibn Aziz Dammam Community College.
Environment After log in into the system, a copy of the shell is given to the user Shell maintains an environment which is distinct from one user to another.
Agenda The Bourne Shell – Part II Special Characters Ambiguous File Reference Variable Names and Values User Created Variables Read-only Variables (Positional.
Linux+ Guide to Linux Certification, Second Edition
The Process CIS 370, Fall 2009 CIS UMassD. The notion of a process In UNIX a process is an instance of a program in execution A job or a task Each process.
Familiarizing with UNIX Commands. UNIX Commands Unix systems are heavily command based. This often makes us feel uncomfortable. Moreover the system is.
Agenda Managing Processes (Jobs) Command Grouping Running jobs in background (bg) Bringing jobs to foreground (fg), Background job status (jobs) Suspending.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
1 Week 8 Creating Simple Shell Scripts. 2 Chapter Objectives  In this chapter, you will :  Learn how to create Shell Scripts  Commenting / Making Portable.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Linux Administration Working with the BASH Shell.
Agenda Customizing a Unix/Linux account Environment Introduction to Start-up Files (.bash_profile,.bashrc,.profile,.kshrc) Safe Methods for Changing Start-up.
Bash Introduction (adapted from chapters 1 and 2 of bash Cookbook by Albing, Vossing, & Newham) CPTE 440 John Beckett.
System Programming and administration CS 308
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to MS-DOS
(Chapter 2) John Carelli, Instructor Kutztown University
The Linux Command Line Chapter 24
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
UNIX and Shell Programming (06CS36)
Module 4 Command Line Skills
UNIX and Shell Programming (06CS36)
The Linux Command Line Chapter 24
Presentation transcript:

CS 497C – Introduction to UNIX Lecture 4: Understanding the UNIX Command Chin-Chih Chang

The PATH: Locating Commands UNIX obtains the list of directories that has to be searched from of an environment variable – PATH. If you evaluate the value of PATH, you’ll find a directory list separated by colons: $ echo $PATH /bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:.

The PATH: Locating Commands There are five directories in this list, and when you issue a command, the system will search this list in the sequence specified to locate and execute it.. indicates the current directory. To know in which directory the command is located, you can use the type command. $ type ls ls is /bin/ls

Internal and External Commands The agency that actually does all this work is known as shell – a command interpreter. Since ls is a file having an independent existence in the /bin directory (or /usr/bin), it is called an external command. Most commands are external in nature. The commands built in shell are known as internal commands.

Internal and External Commands The type command itself is a shell built-in. Whether or not you are able to execute it depends on the shell you use. In some versions of the C shell, the type command won’t work. In this case, which or whereis can be used. The shell uses its internal command even though there is an external command of the same name.

Command Structure An UNIX command is composed of two parts: command and argument. Commands and arguments are separated by any number of spaces or tabs know as whitespace. $ ls-l ls-l: Command not found. The argument that begins with a – symbol is called an option.

Options and Filenames Every command has a fixed set of options. The command with its arguments and options is entered in one line that is referred to as the command line. Some commands accept a single filename, some accept more than one filenames. Wrong options will be indicated. An option can have its own arguments. pine –f mail-may

Combining Options Options that begin with a – sign can normally be combined with only one – sign. For instance, this command has three options: ls –l –a -t The -l option provides most details of a file’s attributes. The –t option sorts files according to the time of modification. The -a option lists the hidden files.

Combining Options You can combine these options in this way: ls –lat ls -atl This facility reduces your typing load. The shell parses (break up) the option combination into separate options. Some commands won’t let you combine options in the way you did just now. tar –cv –f /dev/fd0 –b 18

Combining Options There are four options here, but two of them (-f and –b) has their own arguments. These arguments are called option parameters. We combined the –c and –v options here. We can combine the –f and –b options, provided that their own parameters are placed in the same sequence. tar –cvfb /dev/fd0 18 The following one won’t work: tar –cvfb 18 /dev/fd0

Exceptions and Variations All commands don’t compulsorily use options and arguments. Commands like clear don’t accept any argument. The who and date commands may or may not be specified with arguments.

Exceptions and Variations The ls command permits more variations: –Without any argument (ls) –With only one option (ls –l) –With only filenames (ls chap01 chap02) –Using a combination of both (ls –la chap01 chap02) This text discusses commands that use options. The vast majority will conform to the option rules that have been discussed but there are some exceptions.

Flexibility of Command Usage UNIX allows you to specify more than one command in the same command line. Each command is separated from the other by a ; (semicolon): who; ls -l The ; is one of special characters that are understood by the shell. These special characters are known as metacharacters.

A Command Line Can Overflow When a command has more characters than the terminal width, it simply overflows to the next line. You may want to spread the command into multiple lines. The shell issues a secondary prompt, usually > (or ?). $ echo “This is a two-line > text message” In C shell you have to enter a \ (backslash).

Flexibility of Command Usage Subsequent commands can be entered at the keyboard without waiting for the prompt. There is a type-ahead buffer (a temporary storage area) which stores all these commands and passes them on for execution. A command may not behave in the way you want because UNIX comes in many flavors.

Flexibility of Command Usage The uname can print system information. $ uname Linux The uname –r command shows the version number of the kernel. $ uname –r