The Online Unix Manual

Similar documents
ACS Unix (Winter Term, ) Page 21

5/20/2007. Touring Essential Programs

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

Unix/Linux: History and Philosophy

System Programming. Unix Shells

Standard. Shells. tcsh. A shell script is a file that contains shell commands that perform a useful function. It is also known as shell program.

What is the Shell. Whenever you login to a Unix system you are placed in a program called the shell. All of your work is done within the shell.

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

5/8/2012. Specifying Instructions to the Shell Chapter 8

EECS2301. Lab 1 Winter 2016

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

Appendix A GLOSSARY. SYS-ED/ Computer Education Techniques, Inc.

Linux shell scripting intro/review

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt

CSE II-Sem)

CISC 220 fall 2011, set 1: Linux basics

Introduction to the UNIX command line

UNIX Kernel. UNIX History

12.1 UNDERSTANDING UNIX SHELL PROGRAMMING LANGUAGE: AN INTRODUCTION Writing a Simple Script Executing a Script

Introduction: What is Unix?

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

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

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

Unix Shells and Other Basic Concepts

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

Introduction to UNIX Shell Exercises

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

Chapter-3. Introduction to Unix: Fundamental Commands

Shells and Shell Programming

Introduction to Shell Scripting

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

Shells and Shell Programming

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

System Programming. Introduction to Unix

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

Bash Programming. Student Workbook

Linux & Shell Programming 2014

Operating Systems, Unix Files and Commands SEEM

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

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Introduction. Let s start with the first set of slides

Basic Shell Commands. Bok, Jong Soon

Linux Systems Administration Getting Started with Linux

CST Algonquin College 2

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science

9.2 Linux Essentials Exam Objectives

22-Sep CSCI 2132 Software Development Lecture 8: Shells, Processes, and Job Control. Faculty of Computer Science, Dalhousie University

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

Shell script. Shell Scripts. A shell script contains a sequence of commands in a text file. Shell is an command language interpreter.

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

Getting Started. Running Utilities. Shells. Special Characters. Special Characters. Chapter 2 Unix Utilities for non-programmers

S E C T I O N O V E R V I E W

85321, Systems Administration Chapter 6: The shell

27-Sep CSCI 2132 Software Development Lab 4: Exploring bash and C Compilation. Faculty of Computer Science, Dalhousie University

Assignment clarifications

UNIX shell scripting

(a) About Unix. History

Introduction to Linux

CS246 Spring14 Programming Paradigm Notes on Linux

Unix Handouts. Shantanu N Kulkarni

Chapter 9. Shell and Kernel

Introduction to Linux Workshop 1

Introduction to Unix: Fundamental Commands

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

Introduction to Linux

The Unix Shell & Shell Scripts

S E C T I O N O V E R V I E W

Week 5 Lesson 5 02/28/18

Shell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved

Systems Programming/ C and UNIX

Unix Internal Assessment-2 solution. Ans:There are two ways of starting a job in the background with the shell s & operator and the nohup command.

CHAPTER 3 SHELL PROGRAMS: SCRIPTS

Introduction to Linux

What is a shell? The shell is interface for user to computer OS.

CSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 Lecture 4 Shell Variables, More Shell Scripts (Thanks to Hal Perkins)

Lecture # 2 Introduction to UNIX (Part 2)

Essential Unix (and Linux) for the Oracle DBA. Revision no.: PPT/2K403/02

Linux Command Line Interface. December 27, 2017

Exercise 1: Basic Tools

Introduction to Supercomputing

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi

Scripting Languages Course 1. Diana Trandabăț

Mills HPC Tutorial Series. Linux Basics I

Prof. Navrati Saxena TA: R. Sachan

A shell can be used in one of two ways:

Oxford University Computing Services. Getting Started with Unix

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

The Command Line. Matthew Bender. Friday 18 th September, CMSC Command Line Workshop

RH033 Red Hat Linux Essentials

What is UNIX? A Little Bit about UNIX and User Interfaces. Adapted from Practical Unix and Programming Hunter College

CS Unix Tools. Lecture 3 Making Bash Work For You Fall Hussam Abu-Libdeh based on slides by David Slater. September 13, 2010

No lectures on Monday!!

Introduction to the Shell

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

CS/CIS 249 SP18 - Intro to Information Security

COMP 4/6262: Programming UNIX

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

Continue reading command lines even after an execution error has caused the abandonment of aline.

Transcription:

ACS-294-001 Unix (Winter Term, 2018-2019) Page 14 The Online Unix Manual Unix comes with a large, built-in manual that is accessible at any time from your terminal. The Online Manual is a collection of files, stored on disk, each of which contains the documentation about one Unix command or topic. The Online Manual can be accessed at any time by using the man command. man cp man man man mv lpr ln How Is the Online Manual Organized? Section 1 Executable programs or shell commands 2 System calls (functions provided by the kernel) 3 Library calls (functions within program libraries) 4 Special files (usually found in /dev) 5 File formats and conventions (e.g. /etc/passwd) 6 Games 7 Miscellaneous (including macro packages and conventions) 8 System administration commands (usually only for root) 9 Kernel routines (nonstandard) The most important section is Section 1. Section 2, 3, 4, and 5 may be important to programmers.

ACS-294-001 Unix (Winter Term, 2018-2019) Page 15 The following conventions apply to the SYNOPSIS section and can be used as a guide in other sections: bold text italic text [-abc] type exactly as shown replace with appropriate argument any or all arguments within [ ] are optional -a -b options delimited by cannot be used together argument argument is repeatable [expression] entire expression within [ ] is repeatable man kill will show the description of kill that resides in Section 1 of the manual; man s 2 kill will show the description of kill that resides in Section 2 of the manual; man -s 7 man will show the description of man in Section 7; man umask will show the description of umask that resides in Section 2 of the manual:

ACS-294-001 Unix (Winter Term, 2018-2019) Page 16 man umask UMASK(2) Linux Programmer's Manual UMASK(2) NAME umask - set file mode creation mask SYNOPSIS #include <sys/types.h> #include <sys/stat.h>commands... At the end of the umask man pages are the following a few lines, which tell us there are other pages related to this one: SEE ALSO chmod(2), mkdir(2), open(2), stat(2), acl(5) COLOPHON This page is part of release 3.54 of the Linux man-pages project. A description of the project, and informaâ[m tion about reporting bugs, can be found at http://www.kernel.org/doc/manpages/. NAME: SYNOPSIS: This is what the command is all about. Official explanation of how to enter the command. DESCRIPTION: Could be divided into two separate sections: Description & Options. FILES: SEE ALSO: This section shows the names of the files that are used by this command. It shows you other places to look in the manual for more information.

ACS-294-001 Unix (Winter Term, 2018-2019) Page 17 A Quick Way to Find Out What a Command Does Sometimes you don t want to view a full manual page and you are interested in just a quick description. If you want to see the Name Section, which is a one line description, you can type man followed by f. man -f date cal date (1) - print or set the system date and time cal (1) - displays a calendar and the date of Easter As a convenience, you can type the single word whatis, instead of man f. whatis date cal date (1) - print or set the system date and time cal (1) - displays a calendar and the date of Easter What if you know what you want to do, but not sure which command(s) to use? You can use man k ( or apropos) followed by specified keywords. man -k what git-blame (1) - Show what revision and author last modified each line of a file git-receive-pack (1) - Receive what is pushed into the repository git-whatchanged (1) - Show logs with difference each commit introduces w (1) - Show who is logged on and what they are doing. w.procps (1) - Show who is logged on and what they are doing. whatis (1) - display one-line manual page descriptions

ACS-294-001 Unix (Winter Term, 2018-2019) Page 18 Command Syntax The Unix Command Line When you enter a command, the entire line that you type is called the command line. A command line can contain multiple commands separated by semicolons. date; ls l; lpq Command Syntax The formal description of how a command must be entered is called the command syntax. Arguments: Options: Options & Parameters Options come right after the command and consist of a (minus sign) followed by a letter. Parameters: Parameters come after the options. ls -a l file1 file2 ls al file1 file2 The Format of a Unix Command: command-name options parameters Whitespace One or more consecutive spaces or tabs. Two important expressions: One or More: You must use at least one of something. Zero or More: It is okay to leave it out.

ACS-294-001 Unix (Winter Term, 2018-2019) Page 19 whatis man cp man man ls l ls al file1 file2 ls who uptime With ls, the default is the set of files in your working directory. The Formal Description of a Command: Syntax The syntax of a command is its official description. The syntax that is used to describe Unix commands follows five simple rules: 1. Items in square brackets ([ ]) are optional. 2. Items not in square brackets are obligatory and must be entered as part of the command. 3. Anything in boldface must be typed exactly as written. 4. Anything in italics must be replaced by an appropriate value. 5. Any parameter that is followed by an ellipsis( ) may be repeated any number of times.

ACS-294-001 Unix (Winter Term, 2018-2019) Page 20 ls [-aabbccddffgghhiikllmnnopqqrrssttuuvwxxz1] [file...] a) The command has 40 options. Since they are optional, they are enclosed in square brackets. b) There is one parameter, file, which is optional. c) The name of the command and the options are printed in boldface. It means that they must be typed exactly as they appear. d) The parameter is in italics. It means that you must replace it with an appropriate value. e) The parameter is followed by. That means that you can use more than one parameter. Since the parameter is optional itself, the Zero or More will apply here. ls ls l ls file1 ls file1 file2 file3 ls f l file4 ls fl file4

ACS-294-001 Unix (Winter Term, 2018-2019) Page 21 The Shell From the beginning, Unix was designed so that the shell is an actual program separated from the main part of the operating system. What is a shell? A shell is a command processor -- a program that reads and interprets the commands that you enter. A shell is a programming language. You can write programs, called script, for a shell to interpret. These scripts can contain regular Unix commands, as well as special shell programming commands. A shell is your main interface into Unix. Using the facilities that are built into your shell, you can create a highly customized environment for yourself. There are several shells. Therefore, you can have a choice as to which interface you want to use. The Bourne Shell Family Bourne shell (sh) The earliest Unix shell developed by Steven Bourne of AT&T Bell Labs. It is still in use. Korn shell Bash (ksh) The Korn shell is an upwards compatible extension to Bourne shell. It was developed by David Korn, a Bell Labs scientist, in the mid-1980s. (bash) Bash stands for the Bourne Again SHell. It is the product of the Free Software Foundation. Bash extends the capabilities of the basic Bourne shell in a manner similar to the Korn shell.

ACS-294-001 Unix (Winter Term, 2018-2019) Page 22 Zsh (zsh) Zsh was developed by Paul Falstad in 1990. Zsh offers all of the important features of the other Unix shells as well as new capabilities. It is popular among programmers and advanced Unix users. The C-Shell Family C-Shell Tcsh (csh) The C-Shell was designed by Bill Joy as the Berkeley Unix alternative to the Bourne shell. The C-Shell offers many advantages over the Bourne shell. It is very popular among experienced Unix users, especially at universities and research organizations. (tcsh) Tcsh is an enhanced C-Shell that offers advanced features. What Shell Should You Use? Worldwide, the most widely used shells are the Bourne shell and its replacement, the Korn shell. However, in the academic, research, and programming communities, the C-Shell is the most popular shell. As a command processor, the C-Shell family provides a good allaround working environment. The programming language used by the Bourne shell family is easier and more pleasant to use than that of the C-Shell.

ACS-294-001 Unix (Winter Term, 2018-2019) Page 23 The Relative Complexity of Different Shells Name of Shell Size of the Man page (bytes) Relative Complexity rc 37,885 1.00 Bourne 44,500 1.17 C-Shell 76,816 2.03 Bash 127,361 3.36 Zsh 133,565 3.53 Korn 141,391 3.73 Tcsh 199,834 5.27 Changing Your Shell Temporarily When you log in, the shell Unix starts automatically is called your login shell. Since a shell is a program itself, you can start a new shell any time by entering the name of that shell. When you are finished with the new shell, you can stop it by entering either the exit command or press ^D, the eof key. You must go back to the login shell before you can log out. Using the C-Shell Shell Variables A shell variable is an item, known by a name, which represents a value of some type. The value of a shell variable can be changed. There are two types of shell variables: 1. Variables that act as off/on switches. 2. Variables that store a particular value as a string of characters.

ACS-294-001 Unix (Winter Term, 2018-2019) Page 24 Shell Variables That Act as Switches: set, unset To turn on switch variables, use the set command. Syntax: set [variable-name] set ignoreeof set filec To turn off a switch, use unset command. unset ignoreeof unset filec To display all shell variables and their current settings, enter the command set without arguments: set If a variable is set, its name will appear in the list. If a variable is unset, its name will not appear. Built-in Shell Variables: Switches Variable Name echo filec ignoreeof nobeep noclobber noglob nonomatch notify verbose Purpose display each command before execution enable filename completion must log out with logout instead of eof key (^D) no beep if filename is ambiguous do not allow redirected output to replace a file inhibit expansion of filenames no error if filename expansion matches nothing notify about job completions at any time display full command after history substitution

ACS-294-001 Unix (Winter Term, 2018-2019) Page 25 Shell Variables That Store Values: set Some of the shell variables can be set by you to modify the shell s behavior. Other values are set by the shell to pass information to you. To set a variable of this type, use the set command with the following syntax: set [variable-name = value] set history=50 Built-in Shell Variables That Store Values Variable Name argv cdpath cwd fignore hardpath histchars history home mail path prompt savehist shell status term time user Purpose list of arguments for current command directories to search to find a subdirectory pathname of current working directory suffixes to ignore during the file name completion no symbolic link pathnames in directory stack the two characters used for history substitution size of the history list pathname of your home directory pathnames where shell should check for mail list of directories to search for programs string of characters used for command prompt number of history lines to save upon logout pathname of the shell program return status of the last command type of terminal you are using threshold value for reporting of command timing name of the userid currently logged in On occasion, you may want to give a variable a value that contains spaces or other special characters. In that case, you must put single quotes around the value.

ACS-294-001 Unix (Winter Term, 2018-2019) Page 26 set prompt='my Own Prompt>' My Own Prompt>echo $prompt My Own Prompt> My Own Prompt>set prompt=' ' echo $prompt Displaying the Value of a Variable: echo The command echo simply displays the value of anything you give it. echo Have a nice day! Have a nice day! To display the value of a single variable, use the echo command with the following syntax: echo $variable-name echo $history 100 set history=200 echo $history 200 echo My working directory is $cwd and my home directory is $home. My working directory is /home/sliao and my home directory is /home/sliao.

ACS-294-001 Unix (Winter Term, 2018-2019) Page 27 Environment Variables The shell variables are used only within the shell to control preferences and settings. There is a whole other set of variables that the shell maintains for passing values between programs. These are called Environment Variables or Global Variables. All environment variables have uppercase names. Common Environment Variables Variable Name EDITOR HOME LOGNAME MAIL MANPATH PAGER PATH SHELL TERM USER Purpose pathname of your text editor pathname of your home directory name of the userid currently logged in pathname of your mail program list of directories to search for manual pages name of the paging program you prefer list of directories to search for programs pathname of the shell program type of terminal you are using name of the userid currently logged in The value of an environment variable is available to any program or shell. Many programs look at the TERM variable to see what type of terminal you are using.

ACS-294-001 Unix (Winter Term, 2018-2019) Page 28 Setting the Value of an Environment Variable setenv The syntax is setenv [variable-name value] setenv TERM vt100 Displaying the Value of Environment Variable(s) printenv The syntax is printenv [variable-name] printenv will display all the environment variables printenv TERM echo echo $TERM How Environment and Shell Variables Are Connected There are six common shell variables that have the same names as environment variables (except that environment variables have uppercase names). 1) home, shell vs. HOME, SHELL home contains the pathname of your home directory and shell contains the pathname of the shell you use. Whenever you log in, Unix automatically sets the values of home and shell (and HOME and SHELL). Your programs will examine these variables from time to time, but you will probably never need to change them yourself.

ACS-294-001 Unix (Winter Term, 2018-2019) Page 29 2) term, path, user vs. TERM, PATH, USER The local variables term, path, and user are tied to the corresponding global variables. Whenever you change a shell variable, the shell will automatically update the corresponding global variable. set term=hello echo $term; echo $TERM hello hello setenv TERM vt100 echo $term; echo $TERM hello vt100 setenv TERM hello set term=vt100 echo $term; echo $TERM vt100 vt100 3) mail vs. MAIL They are not connected. Commands That Are Built Into the Shell When you enter a command, the shell will break the command line into parts. The first part of each command is the name, the other parts are options and parameters. Some commands are internal to the shell. The shell can interpret these commands directly. The Number of Internal Commands in Each Shell Name of Shell Bourne 32 Korn 43 Bash 50 C-Shell 52 Tcsh 56 Zsh 73 Internal Commands