GAWK: Effective AWK Programming a User’S Guide for GNU Awk Edition 3 July, 2009

Total Page:16

File Type:pdf, Size:1020Kb

GAWK: Effective AWK Programming a User’S Guide for GNU Awk Edition 3 July, 2009 GAWK: Effective AWK Programming A User's Guide for GNU Awk Edition 3 July, 2009 Arnold D. Robbins \To boldly go where no man has gone before" is a Registered Trademark of Paramount Pictures Corporation. Published by: Free Software Foundation 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA Phone: +1-617-542-5942 Fax: +1-617-542-2652 Email: [email protected] URL: http://www.gnu.org/ ISBN 1-882114-28-0 Copyright c 1989, 1991, 1992, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2009 Free Software Foundation, Inc. This is Edition 3 of GAWK: Effective AWK Programming: A User's Guide for GNUAwk, for the 3.1.7 (or later) version of the GNU implementation of AWK. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with the Invariant Sections being \GNU General Public License", the Front-Cover texts being (a) (see below), and with the Back-Cover Texts being (b) (see below). A copy of the license is included in the section entitled \GNU Free Documentation License". a. \A GNU Manual" b. \You have the freedom to copy and modify this GNU manual. Buying copies from the FSF supports it in developing GNU and promoting software freedom." Cover art by Etienne Suvasa. To Miriam, for making me complete. To Chana, for the joy you bring us. To Rivka, for the exponential increase. To Nachum, for the added dimension. To Malka, for the new beginning. i Short Contents Foreword :::::::::::::::::::::::::::::::::::::::::::::::: 1 Preface ::::::::::::::::::::::::::::::::::::::::::::::::: 3 1 Getting Started with awk :::::::::::::::::::::::::::::: 11 2 Regular Expressions :::::::::::::::::::::::::::::::::: 24 3 Reading Input Files :::::::::::::::::::::::::::::::::: 36 4 Printing Output ::::::::::::::::::::::::::::::::::::: 58 5 Expressions ::::::::::::::::::::::::::::::::::::::::: 75 6 Patterns, Actions, and Variables :::::::::::::::::::::::: 96 7 Arrays in awk :::::::::::::::::::::::::::::::::::::: 119 8 Functions :::::::::::::::::::::::::::::::::::::::::: 130 9 Internationalization with gawk ::::::::::::::::::::::::: 160 10 Advanced Features of gawk ::::::::::::::::::::::::::: 169 11 Running awk and gawk ::::::::::::::::::::::::::::::: 177 12 A Library of awk Functions ::::::::::::::::::::::::::: 186 13 Practical awk Programs :::::::::::::::::::::::::::::: 215 A The Evolution of the awk Language::::::::::::::::::::: 257 B Installing gawk ::::::::::::::::::::::::::::::::::::: 265 C Implementation Notes:::::::::::::::::::::::::::::::: 285 D Basic Programming Concepts ::::::::::::::::::::::::: 301 Glossary :::::::::::::::::::::::::::::::::::::::::::::: 307 GNU General Public License :::::::::::::::::::::::::::::: 317 GNU Free Documentation License ::::::::::::::::::::::::: 328 Index ::::::::::::::::::::::::::::::::::::::::::::::::: 336 ii GAWK: Effective AWK Programming Table of Contents Foreword :::::::::::::::::::::::::::::::::::::::::::: 1 Preface :::::::::::::::::::::::::::::::::::::::::::::: 3 History of awk and gawk ::::::::::::::::::::::::::::::::::::::::::::: 3 A Rose by Any Other Name ::::::::::::::::::::::::::::::::::::::::: 4 Using This Book :::::::::::::::::::::::::::::::::::::::::::::::::::: 5 Typographical Conventions :::::::::::::::::::::::::::::::::::::::::: 6 The GNU Project and This Book:::::::::::::::::::::::::::::::::::: 7 How to Contribute :::::::::::::::::::::::::::::::::::::::::::::::::: 8 Acknowledgments ::::::::::::::::::::::::::::::::::::::::::::::::::: 9 1 Getting Started with awk ::::::::::::::::::::: 11 1.1 How to Run awk Programs :::::::::::::::::::::::::::::::::::: 11 1.1.1 One-Shot Throwaway awk Programs :::::::::::::::::::::: 11 1.1.2 Running awk Without Input Files :::::::::::::::::::::::: 12 1.1.3 Running Long Programs ::::::::::::::::::::::::::::::::: 12 1.1.4 Executable awk Programs :::::::::::::::::::::::::::::::: 13 1.1.5 Comments in awk Programs :::::::::::::::::::::::::::::: 14 1.1.6 Shell-Quoting Issues :::::::::::::::::::::::::::::::::::::: 14 1.1.6.1 Quoting in MS-DOS Batch Files ::::::::::::::::::::: 16 1.2 Data Files for the Examples ::::::::::::::::::::::::::::::::::: 16 1.3 Some Simple Examples:::::::::::::::::::::::::::::::::::::::: 17 1.4 An Example with Two Rules :::::::::::::::::::::::::::::::::: 19 1.5 A More Complex Example :::::::::::::::::::::::::::::::::::: 20 1.6 awk Statements Versus Lines :::::::::::::::::::::::::::::::::: 21 1.7 Other Features of awk ::::::::::::::::::::::::::::::::::::::::: 22 1.8 When to Use awk ::::::::::::::::::::::::::::::::::::::::::::: 23 2 Regular Expressions::::::::::::::::::::::::::: 24 2.1 How to Use Regular Expressions :::::::::::::::::::::::::::::: 24 2.2 Escape Sequences ::::::::::::::::::::::::::::::::::::::::::::: 25 2.3 Regular Expression Operators ::::::::::::::::::::::::::::::::: 27 2.4 Using Character Lists ::::::::::::::::::::::::::::::::::::::::: 29 2.5 gawk-Specific Regexp Operators ::::::::::::::::::::::::::::::: 31 2.6 Case Sensitivity in Matching :::::::::::::::::::::::::::::::::: 32 2.7 How Much Text Matches? ::::::::::::::::::::::::::::::::::::: 33 2.8 Using Dynamic Regexps::::::::::::::::::::::::::::::::::::::: 34 2.9 Where You Are Makes A Difference ::::::::::::::::::::::::::: 35 iii 3 Reading Input Files ::::::::::::::::::::::::::: 36 3.1 How Input Is Split into Records ::::::::::::::::::::::::::::::: 36 3.2 Examining Fields ::::::::::::::::::::::::::::::::::::::::::::: 39 3.3 Nonconstant Field Numbers ::::::::::::::::::::::::::::::::::: 40 3.4 Changing the Contents of a Field:::::::::::::::::::::::::::::: 41 3.5 Specifying How Fields Are Separated :::::::::::::::::::::::::: 43 3.5.1 Using Regular Expressions to Separate Fields ::::::::::::: 44 3.5.2 Making Each Character a Separate Field ::::::::::::::::: 45 3.5.3 Setting FS from the Command Line :::::::::::::::::::::: 45 3.5.4 Field-Splitting Summary ::::::::::::::::::::::::::::::::: 46 3.6 Reading Fixed-Width Data:::::::::::::::::::::::::::::::::::: 48 3.7 Multiple-Line Records::::::::::::::::::::::::::::::::::::::::: 49 3.8 Explicit Input with getline :::::::::::::::::::::::::::::::::: 52 3.8.1 Using getline with No Arguments ::::::::::::::::::::::: 52 3.8.2 Using getline into a Variable :::::::::::::::::::::::::::: 53 3.8.3 Using getline from a File ::::::::::::::::::::::::::::::: 53 3.8.4 Using getline into a Variable from a File :::::::::::::::: 54 3.8.5 Using getline from a Pipe::::::::::::::::::::::::::::::: 54 3.8.6 Using getline into a Variable from a Pipe ::::::::::::::: 56 3.8.7 Using getline from a Coprocess ::::::::::::::::::::::::: 56 3.8.8 Using getline into a Variable from a Coprocess :::::::::: 56 3.8.9 Points to Remember About getline ::::::::::::::::::::: 56 3.8.10 Summary of getline Variants::::::::::::::::::::::::::: 57 4 Printing Output ::::::::::::::::::::::::::::::: 58 4.1 The print Statement ::::::::::::::::::::::::::::::::::::::::: 58 4.2 Examples of print Statements :::::::::::::::::::::::::::::::: 58 4.3 Output Separators :::::::::::::::::::::::::::::::::::::::::::: 60 4.4 Controlling Numeric Output with print::::::::::::::::::::::: 60 4.5 Using printf Statements for Fancier Printing ::::::::::::::::: 61 4.5.1 Introduction to the printf Statement :::::::::::::::::::: 61 4.5.2 Format-Control Letters::::::::::::::::::::::::::::::::::: 61 4.5.3 Modifiers for printf Formats :::::::::::::::::::::::::::: 63 4.5.4 Examples Using printf :::::::::::::::::::::::::::::::::: 65 4.6 Redirecting Output of print and printf :::::::::::::::::::::: 66 4.7 Special File Names in gawk :::::::::::::::::::::::::::::::::::: 69 4.7.1 Special Files for Standard Descriptors :::::::::::::::::::: 69 4.7.2 Special Files for Process-Related Information ::::::::::::: 70 4.7.3 Special Files for Network Communications :::::::::::::::: 71 4.7.4 Special File Name Caveats ::::::::::::::::::::::::::::::: 71 4.8 Closing Input and Output Redirections :::::::::::::::::::::::: 71 iv GAWK: Effective AWK Programming 5 Expressions :::::::::::::::::::::::::::::::::::: 75 5.1 Constant Expressions ::::::::::::::::::::::::::::::::::::::::: 75 5.1.1 Numeric and String Constants:::::::::::::::::::::::::::: 75 5.1.2 Octal and Hexadecimal Numbers ::::::::::::::::::::::::: 75 5.1.3 Regular Expression Constants :::::::::::::::::::::::::::: 76 5.2 Using Regular Expression Constants::::::::::::::::::::::::::: 76 5.3 Variables:::::::::::::::::::::::::::::::::::::::::::::::::::::: 78 5.3.1 Using Variables in a Program::::::::::::::::::::::::::::: 78 5.3.2 Assigning Variables on the Command Line:::::::::::::::: 78 5.4 Conversion of Strings and Numbers:::::::::::::::::::::::::::: 79 5.5 Arithmetic Operators ::::::::::::::::::::::::::::::::::::::::: 81 5.6 String Concatenation:::::::::::::::::::::::::::::::::::::::::: 82 5.7 Assignment Expressions ::::::::::::::::::::::::::::::::::::::: 83 5.8 Increment and Decrement Operators :::::::::::::::::::::::::: 86 5.9 True and False in awk ::::::::::::::::::::::::::::::::::::::::: 87 5.10 Variable Typing and Comparison Expressions :::::::::::::::: 87 5.10.1 String Type Versus Numeric Type ::::::::::::::::::::::: 88 5.10.2 Comparison Operators :::::::::::::::::::::::::::::::::: 89 5.11 Boolean Expressions ::::::::::::::::::::::::::::::::::::::::: 91 5.12 Conditional Expressions:::::::::::::::::::::::::::::::::::::: 92 5.13 Function Calls ::::::::::::::::::::::::::::::::::::::::::::::: 93 5.14 Operator Precedence (How Operators Nest) :::::::::::::::::: 94 6 Patterns, Actions, and Variables ::::::::::::: 96 6.1
Recommended publications
  • At—At, Batch—Execute Commands at a Later Time
    at—at, batch—execute commands at a later time at [–csm] [–f script] [–qqueue] time [date] [+ increment] at –l [ job...] at –r job... batch at and batch read commands from standard input to be executed at a later time. at allows you to specify when the commands should be executed, while jobs queued with batch will execute when system load level permits. Executes commands read from stdin or a file at some later time. Unless redirected, the output is mailed to the user. Example A.1 1 at 6:30am Dec 12 < program 2 at noon tomorrow < program 3 at 1945 pm August 9 < program 4 at now + 3 hours < program 5 at 8:30am Jan 4 < program 6 at -r 83883555320.a EXPLANATION 1. At 6:30 in the morning on December 12th, start the job. 2. At noon tomorrow start the job. 3. At 7:45 in the evening on August 9th, start the job. 4. In three hours start the job. 5. At 8:30 in the morning of January 4th, start the job. 6. Removes previously scheduled job 83883555320.a. awk—pattern scanning and processing language awk [ –fprogram–file ] [ –Fc ] [ prog ] [ parameters ] [ filename...] awk scans each input filename for lines that match any of a set of patterns specified in prog. Example A.2 1 awk '{print $1, $2}' file 2 awk '/John/{print $3, $4}' file 3 awk -F: '{print $3}' /etc/passwd 4 date | awk '{print $6}' EXPLANATION 1. Prints the first two fields of file where fields are separated by whitespace. 2. Prints fields 3 and 4 if the pattern John is found.
    [Show full text]
  • The /Proc File System
    09 0430 CH07 5/22/01 10:30 AM Page 147 7 The /proc File System TRY INVOKING THE mount COMMAND WITHOUT ARGUMENTS—this displays the file systems currently mounted on your GNU/Linux computer.You’ll see one line that looks like this: none on /proc type proc (rw) This is the special /proc file system. Notice that the first field, none, indicates that this file system isn’t associated with a hardware device such as a disk drive. Instead, /proc is a window into the running Linux kernel. Files in the /proc file system don’t corre- spond to actual files on a physical device. Instead, they are magic objects that behave like files but provide access to parameters, data structures, and statistics in the kernel. The “contents” of these files are not always fixed blocks of data, as ordinary file con- tents are. Instead, they are generated on the fly by the Linux kernel when you read from the file.You can also change the configuration of the running kernel by writing to certain files in the /proc file system. Let’s look at an example: % ls -l /proc/version -r--r--r-- 1 root root 0 Jan 17 18:09 /proc/version Note that the file size is zero; because the file’s contents are generated by the kernel, the concept of file size is not applicable.Also, if you try this command yourself, you’ll notice that the modification time on the file is the current time. 09 0430 CH07 5/22/01 10:30 AM Page 148 148 Chapter 7 The /proc File System What’s in this file? The contents of /proc/version consist of a string describing the Linux kernel version number.
    [Show full text]
  • A.5.1. Linux Programming and the GNU Toolchain
    Making the Transition to Linux A Guide to the Linux Command Line Interface for Students Joshua Glatt Making the Transition to Linux: A Guide to the Linux Command Line Interface for Students Joshua Glatt Copyright © 2008 Joshua Glatt Revision History Revision 1.31 14 Sept 2008 jg Various small but useful changes, preparing to revise section on vi Revision 1.30 10 Sept 2008 jg Revised further reading and suggestions, other revisions Revision 1.20 27 Aug 2008 jg Revised first chapter, other revisions Revision 1.10 20 Aug 2008 jg First major revision Revision 1.00 11 Aug 2008 jg First official release (w00t) Revision 0.95 06 Aug 2008 jg Second beta release Revision 0.90 01 Aug 2008 jg First beta release License This document is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License [http:// creativecommons.org/licenses/by-nc-sa/3.0/us/]. Legal Notice This document is distributed in the hope that it will be useful, but it is provided “as is” without express or implied warranty of any kind; without even the implied warranties of merchantability or fitness for a particular purpose. Although the author makes every effort to make this document as complete and as accurate as possible, the author assumes no responsibility for errors or omissions, nor does the author assume any liability whatsoever for incidental or consequential damages in connection with or arising out of the use of the information contained in this document. The author provides links to external websites for informational purposes only and is not responsible for the content of those websites.
    [Show full text]
  • Bash Crash Course + Bc + Sed + Awk∗
    Bash Crash course + bc + sed + awk∗ Andrey Lukyanenko, CSE, Aalto University Fall, 2011 There are many Unix shell programs: bash, sh, csh, tcsh, ksh, etc. The comparison of those can be found on-line 1. We will primary focus on the capabilities of bash v.4 shell2. 1. Each bash script can be considered as a text file which starts with #!/bin/bash. It informs the editor or interpretor which tries to open the file, what to do with the file and how should it be treated. The special character set in the beginning #! is a magic number; check man magic and /usr/share/file/magic on existing magic numbers if interested. 2. Each script (assume you created “scriptname.sh file) can be invoked by command <dir>/scriptname.sh in console, where <dir> is absolute or relative path to the script directory, e.g., ./scriptname.sh for current directory. If it has #! as the first line it will be invoked by this command, otherwise it can be called by command bash <dir>/scriptname.sh. Notice: to call script as ./scriptname.sh it has to be executable, i.e., call command chmod 555 scriptname.sh before- hand. 3. Variable in bash can be treated as integers or strings, depending on their value. There are set of operations and rules available for them. For example: #!/bin/bash var1=123 # Assigns value 123 to var1 echo var1 # Prints ’var1’ to output echo $var1 # Prints ’123’ to output var2 =321 # Error (var2: command not found) var2= 321 # Error (321: command not found) var2=321 # Correct var3=$var2 # Assigns value 321 from var2 to var3 echo $var3 # Prints ’321’ to output
    [Show full text]
  • Useful Commands in Linux and Other Tools for Quality Control
    Useful commands in Linux and other tools for quality control Ignacio Aguilar INIA Uruguay 05-2018 Unix Basic Commands pwd show working directory ls list files in working directory ll as before but with more information mkdir d make a directory d cd d change to directory d Copy and moving commands To copy file cp /home/user/is . To copy file directory cp –r /home/folder . to move file aa into bb in folder test mv aa ./test/bb To delete rm yy delete the file yy rm –r xx delete the folder xx Redirections & pipe Redirection useful to read/write from file !! aa < bb program aa reads from file bb blupf90 < in aa > bb program aa write in file bb blupf90 < in > log Redirections & pipe “|” similar to redirection but instead to write to a file, passes content as input to other command tee copy standard input to standard output and save in a file echo copy stream to standard output Example: program blupf90 reads name of parameter file and writes output in terminal and in file log echo par.b90 | blupf90 | tee blup.log Other popular commands head file print first 10 lines list file page-by-page tail file print last 10 lines less file list file line-by-line or page-by-page wc –l file count lines grep text file find lines that contains text cat file1 fiel2 concatenate files sort sort file cut cuts specific columns join join lines of two files on specific columns paste paste lines of two file expand replace TAB with spaces uniq retain unique lines on a sorted file head / tail $ head pedigree.txt 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 0 0 9 0 0 10
    [Show full text]
  • The AWK Programming Language
    The Programming ~" ·. Language PolyAWK- The Toolbox Language· Auru:o V. AHo BRIAN W.I<ERNIGHAN PETER J. WEINBERGER TheAWK4 Programming~ Language TheAWI(. Programming~ Language ALFRED V. AHo BRIAN w. KERNIGHAN PETER J. WEINBERGER AT& T Bell Laboratories Murray Hill, New Jersey A ADDISON-WESLEY•• PUBLISHING COMPANY Reading, Massachusetts • Menlo Park, California • New York Don Mills, Ontario • Wokingham, England • Amsterdam • Bonn Sydney • Singapore • Tokyo • Madrid • Bogota Santiago • San Juan This book is in the Addison-Wesley Series in Computer Science Michael A. Harrison Consulting Editor Library of Congress Cataloging-in-Publication Data Aho, Alfred V. The AWK programming language. Includes index. I. AWK (Computer program language) I. Kernighan, Brian W. II. Weinberger, Peter J. III. Title. QA76.73.A95A35 1988 005.13'3 87-17566 ISBN 0-201-07981-X This book was typeset in Times Roman and Courier by the authors, using an Autologic APS-5 phototypesetter and a DEC VAX 8550 running the 9th Edition of the UNIX~ operating system. -~- ATs.T Copyright c 1988 by Bell Telephone Laboratories, Incorporated. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopy­ ing, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. Published simultaneously in Canada. UNIX is a registered trademark of AT&T. DEFGHIJ-AL-898 PREFACE Computer users spend a lot of time doing simple, mechanical data manipula­ tion - changing the format of data, checking its validity, finding items with some property, adding up numbers, printing reports, and the like.
    [Show full text]
  • Regular Expressions and Sed &
    Regular expressions and sed & awk Regular expressions • Key to powerful, efficient, and flexible text processing by allowing for variable information in the search patterns • Defined as a string composed of letters, numbers, and special symbols, that defines one or more strings • You have already used them in selecting files when you used asterisk (*) and question mark characters to select filenames • Used by several Unix utilities such as ed, vi, emacs, grep, sed, and awk to search for and replace strings – Checking the author, subject, and date of each message in a given mail folder egrep "ˆ(From|Subject|Date): " <folder> – The quotes above are not a part of the regular expression but are needed by the command shell – The metacharacter | (or) is a convenient one to combine multiple expressions into a single expression to match any of the individual expressions contained therein ∗ The subexpressions are known as alternatives • A regular expression is composed of characters, delimiters, simple strings, special characters, and other metacharacters defined below • Characters – A character is any character on the keyboard except the newline character ’\n’ – Most characters represent themselves within a regular expression – All the characters that represent themselves are called literals – A special character is one that does not represent itself (such as a metacharacter) and needs to be quoted ∗ The metacharacters in the example above (with egrep) are ", ˆ, (, |, and ) – We can treat the regular expressions as a language in which the literal characters
    [Show full text]
  • An AWK to C++ Translator
    An AWK to C++ Translator Brian W. Kernighan Bell Laboratories Murray Hill, NJ 07974 [email protected] ABSTRACT This paper describes an experiment to produce an AWK to C++ translator and an AWK class definition and supporting library. The intent is to generate efficient and read- able C++, so that the generated code will run faster than interpreted AWK and can also be modified and extended where an AWK program could not be. The AWK class and library can also be used independently of the translator to access AWK facilities from C++ pro- grams. 1. Introduction An AWK program [1] is a sequence of pattern-action statements: pattern { action } pattern { action } ... A pattern is a regular expression, numeric expression, string expression, or combination of these; an action is executable code similar to C. The operation of an AWK program is for each input line for each pattern if the pattern matches the input line do the action Variables in an AWK program contain string or numeric values or both according to context; there are built- in variables for useful values such as the input filename and record number. Operators work on strings or numbers, coercing the types of their operands as necessary. Arrays have arbitrary subscripts (‘‘associative arrays’’). Input is read and input lines are split into fields, called $1, $2, etc. Control flow statements are like those of C: if-else, while, for, do. There are user-defined and built-in functions for arithmetic, string, regular expression pattern-matching, and input and output to/from arbitrary files and processes.
    [Show full text]
  • User's Guide for Linux and UNIX
    Centrify Server Suite User’s Guide for Linux and UNIX July 2021 (release 2021) Centrify Corporation • • • • • • Legal Notice This document and the software described in this document are furnished under and are subject to the terms of a license agreement or a non-disclosure agreement. Except as expressly set forth in such license agreement or non-disclosure agreement, Centrify Corporation provides this document and the software described in this document “as is” without warranty of any kind, either express or implied, including, but not limited to, the implied warranties of merchantability or fitness for a particular purpose. Some states do not allow disclaimers of express or implied warranties in certain transactions; therefore, this statement may not apply to you. This document and the software described in this document may not be lent, sold, or given away without the prior written permission of Centrify Corporation, except as otherwise permitted by law. Except as expressly set forth in such license agreement or non-disclosure agreement, no part of this document or the software described in this document may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, or otherwise, without the prior written consent of Centrify Corporation. Some companies, names, and data in this document are used for illustration purposes and may not represent real companies, individuals, or data. This document could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein. These changes may be incorporated in new editions of this document. Centrify Corporation may make improvements in or changes to the software described in this document at any time.
    [Show full text]
  • A Crash Course on UNIX
    AA CCrraasshh CCoouurrssee oonn UUNNIIXX UNIX is an "operating system". Interface between user and data stored on computer. A Windows-style interface is not required. Many flavors of UNIX (and windows interfaces). Solaris, Mandrake, RedHat (fvwm, Gnome, KDE), ... Most UNIX users use "shells" (or "xterms"). UNIX windows systems do provide some Microsoft Windows functionality. TThhee SShheellll A shell is a command-line interface to UNIX. Also many flavors, e.g. sh, bash, csh, tcsh. The shell provides commands and functionality beyond the basic UNIX tools. E.g., wildcards, shell variables, loop control, etc. For this tutorial, examples use tcsh in RedHat Linux running Gnome. Differences are minor for the most part... BBaassiicc CCoommmmaannddss You need these to survive: ls, cd, cp, mkdir, mv. Typically these are UNIX (not shell) commands. They are actually programs that someone has written. Most commands such as these accept (or require) "arguments". E.g. ls -a [show all files, incl. "dot files"] mkdir ASTR688 [create a directory] cp myfile backup [copy a file] See the handout for a list of more commands. AA WWoorrdd AAbboouutt DDiirreeccttoorriieess Use cd to change directories. By default you start in your home directory. E.g. /home/dcr Handy abbreviations: Home directory: ~ Someone else's home directory: ~user Current directory: . Parent directory: .. SShhoorrttccuuttss To return to your home directory: cd To return to the previous directory: cd - In tcsh, with filename completion (on by default): Press TAB to complete filenames as you type. Press Ctrl-D to print a list of filenames matching what you have typed so far. Completion works with commands and variables too! Use ↑, ↓, Ctrl-A, & Ctrl-E to edit previous lines.
    [Show full text]
  • Man Pages Section 2 System Calls
    man pages section 2: System Calls Part No: E29032 October 2012 Copyright © 1993, 2012, Oracle and/or its affiliates. All rights reserved. This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited. The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing. If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, the following notice is applicable: U.S. GOVERNMENT END USERS. Oracle programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, delivered to U.S. Government end users are "commercial computer software" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of the programs, including anyoperating system, integrated software, any programs installed on the hardware, and/or documentation, shall be subject to license terms and license restrictions applicable to the programs. No other rights are granted to the U.S. Government. This software or hardware is developed for general use in a variety of information management applications.
    [Show full text]
  • Intro to Unix-1-2014
    Unix Introduction Getting started with the Unix Operating System What is an Operating System? A computer Operating System, or “OS” What is a computer operating system? Where? What does an OS provide? Insulation from hardware Allocation of resources Utility Functions (often blurring the line between OS and applications) The problem There are numerous past, present, and future storage technologies Each of these requires unique procedures for getting data to and from the device. But, it is unreasonable to expect each application to understand each device. The solution The OS provides simple "abstract devices” for storage: Random access (disks, solid state) Sequential access (tapes) Applications talk to the abstract devices, the OS translates and talks to the actual devices. The OS provides a layer of insulation from these details. Beyond storage Insulation roles of the OS extends to most aspects of computer hardware, including User interface devices Network and communications Memory Expansion busses … OS-Hardware pairing OS is necessarily closely tied to particular hardware. OS used to always be supplied by the hardware vendor. What does an OS provide? Insulation from hardware Allocation of resources Utility About that “disk” abstraction… The disk abstraction represents a disk as quantity of storage. An application is insulated from the hardware details of exactly how the data are stored. An application can read or write from any location in that quantity of storage. The problem The disk abstraction provides no structure for data stored in the disk. If multiple applications want to use the same disk, they must agree on a way to structure data.
    [Show full text]