Answers to Even- Numbered Exercises

Similar documents
The Linux Operating System and Linux-Related Issues

Hands-On UNIX Exercise:

Command Line Crash Course For Unix

Thirty Useful Unix Commands

Command Line - Part 1

AN INTRODUCTION TO UNIX

Command-Line Operations : The Shell. Don't fear the command line...

Cisco Networking Academy Program Curriculum Scope & Sequence. Fundamentals of UNIX version 2.0 (July, 2002)

A Crash Course on UNIX

Tutorial 0A Programming on the command line

Lecture 4. Regular Expressions grep and sed intro

Unix Sampler. PEOPLE whoami id who

Introduction to Shell Programming

Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script

An Introduction to the Linux Command Shell For Beginners

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, Introduction 1. 2 Invoking Shell Scripts 2

USEFUL UNIX COMMANDS

UNIX Intro and Basic C shell Scripting

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

CMSC 216 UNIX tutorial Fall 2010

Introduction to the UNIX Operating System and Open Windows Desktop Environment

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment

HP-UX Essentials and Shell Programming Course Summary

LECTURE-7. Introduction to DOS. Introduction to UNIX/LINUX OS. Introduction to Windows. Topics:

RECOVER ( 8 ) Maintenance Procedures RECOVER ( 8 )

KWIC Implemented with Pipe Filter Architectural Style

Unix the Bare Minimum

QUICK START BASIC LINUX AND G++ COMMANDS. Prepared By: Pn. Azura Bt Ishak

Lecture 18 Regular Expressions

Tutorial Guide to the IS Unix Service

CPSC2800: Linux Hands-on Lab #3 Explore Linux file system and file security. Project 3-1

1 Basic commands. 2 Terminology. CS61B, Fall 2009 Simple UNIX Commands P. N. Hilfinger

Fred Hantelmann LINUX. Start-up Guide. A self-contained introduction. With 57 Figures. Springer

Introduction to Mac OS X

ICS 351: Today's plan

Linux command line. An introduction to the Linux command line for genomics. Susan Fairley

Data Intensive Computing Handout 5 Hadoop

Answers to Even- Numbered Exercises

A UNIX/Linux in a nutshell

CSIL MiniCourses. Introduction To Unix (I) John Lekberg Sean Hogan Cannon Matthews Graham Smith. Updated on:

UNIX Tutorial for Beginners

INASP: Effective Network Management Workshops

Syntax: cd <Path> Or cd $<Custom/Standard Top Name>_TOP (In CAPS)

Data Intensive Computing Handout 6 Hadoop

Higher National Unit Specification. General information for centres. Multi User Operating Systems. Unit code: DH3A 34

Introduction to Linux and Cluster Basics for the CCR General Computing Cluster

Basic Linux & Package Management. Original slides from GTFO Security

Operating Systems. Study this screen display and answer these questions.

Automated Offsite Backup with rdiff-backup

Hadoop Shell Commands

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003

Hadoop Shell Commands

IBM i Version 7.2. Systems management Advanced job scheduler

Introduction to. UNIX Bob Booth December 2004 AP-UNIX2. University of Sheffield

Shree M. & N. Virani Science College. DOS Commands. By Milan Kothari. Yogidham, Kalawad Road, Rajkot 5 Ph :

CPSC 2800 Linux Hands-on Lab #7 on Linux Utilities. Project 7-1

This presentation explains how to monitor memory consumption of DataStage processes during run time.

CNC Transfer. Operating Manual

Regular Expressions. Abstract

UNIX, Shell Scripting and Perl Introduction

HARFORD COMMUNITY COLLEGE 401 Thomas Run Road Bel Air, MD Course Outline CIS INTRODUCTION TO UNIX

A Tiny Queuing System for Blast Servers

Bitrix Site Manager 4.0. Quick Start Guide to Newsletters and Subscriptions

DOS Command Reference

Linux Overview. Local facilities. Linux commands. The vi (gvim) editor

Agenda. Using HPC Wales 2

Using Secure4Audit in an IRIX 6.5 Environment

Introduction to the UNIX Operating System on IT Systems

Birmingham Environment for Academic Research. Introduction to Linux Quick Reference Guide. Research Computing Team V1.0

Open Source Computational Fluid Dynamics

HDFS File System Shell Guide

Using SVN to Manage Source RTL

Extreme computing lab exercises Session one

File System Shell Guide

Cygwin command line windows. Get that Linux feeling - on Windows

New Lab Intro to KDE Terminal Konsole

Bash shell programming Part II Control statements

Higher National Unit Specification. General information for centres. Unit title: Multi User Operating Systems. Unit code: D76G 34

Using the Radmind Command Line Tools to. Maintain Multiple Mac OS X Machines

CS10110 Introduction to personal computer equipment

Running Qshell. Chapter 2 QSHELL IN AN INTERACTIVE JOB

A Method for Cleaning Clinical Trial Analysis Data Sets

Lecture 4: Writing shell scripts

PharmaSUG Paper AD11

File Manager User Guide

Answers to Even-numbered Exercises

CS Unix Tools & Scripting Lecture 9 Shell Scripting

Linux System Administration on Red Hat

Unix Scripts and Job Scheduling

L01 Introduction to the Unix OS

STEP 4 : GETTING LIGHTTPD TO WORK ON YOUR SEAGATE GOFLEX SATELLITE

Using Logon Agent for Transparent User Identification

Program 5 - Processes and Signals (100 points)

Getting Started with the Cadence Software

List of some usual things to test in an application

4.10 Maintain Database

Introduction to Running Hadoop on the High Performance Clusters at the Center for Computational Research

Basic Hadoop Programming Skills

Basic Requirements...2. Software Requirements...2. Mailbox...2. Gatekeeper...3. Plan Your Setup...3. Meet Extreme Processing...3. Script Editor...

Version Control. Luka Milovanov

Transcription:

Answers to Even- 5 Numbered Exercises from page 163 1. What does the shell ordinarily do while a command is executing? What should you do if you do not want to wait for a command to finish before running another command? 2. Using sort as a filter, rewrite the following sequence of commands: $ sort list > temp $ lpr temp $ rm temp $ cat list sort lpr 3. What is a PID number? Why are they useful when you run processes in the background? 4. Assume that the following files are in the working directory: $ ls intro notesb ref2 section1 section3 section4b notesa ref1 ref3 section2 section4a sentrev Give commands for each of the following, using wildcards to express filenames with as few characters as possible. 1

2 Chapter 5 Answers to Exercises a. List all files that begin with section. $ ls section* b. List the section1, section2, and section3 files only. $ ls section[1-3] c. List the intro file only. $ ls i* d. List the section1, section3, ref1, and ref3 files. $ ls *[13] 5. Refer to the documentation of utilities in Part III or the man pages to determine what commands will a. Output the number of lines in the standard input that contain the word a or A. b. Output only the names of the files in the working directory that contain the pattern $(. c. List the files in the working directory in their reverse alphabetical order. d. Send a list of files in the working directory to the printer, sorted by size. 6. Give a command to a. Redirect the standard output from a sort command into a file named phone_list. Assume that the input file is named numbers. $ sort numbers > phone_list b. Translate all occurrences of characters [ and { to the character (, and all occurrences of the characters ] and } to the character ) in the file permdemos.c. (Hint: Refer to tr on page 1362 in Part III.) $ cat permdemos.c tr '[{}]' '(())' or $ tr '[{}]' '(())' < permdemos.c c. Create a file named book that contains the contents of two other files: part1 and part2. $ cat part[12] > book 7. The lpr and sort utilities accept input either from a file named on the command line or from standard input. a. Name two other utilities that function in a similar manner. b. Name a utility that accepts its input only from standard input.

Chapter 5 Answers to Exercises 3 8. Give an example of a command that uses grep a. With both input and output redirected. $ grep \$Id < *.c > id_list b. With only input redirected. $ grep -i suzi < addresses c. With only output redirected. $ grep -il memo *.txt > memoranda_files d. Within a pipe. $ file /usr/bin/* grep "Again shell script" sort -r In which of the preceding is grep used as a filter? Example d uses grep as a filter. 9. Explain the following error message. What filenames would a subsequent ls display? $ ls abc abd abe abf abg abh $ rm abc ab* rm: cannot remove 'abc': No such file or directory Advanced Exercises Advanced Exercises 10. When you use the redirect output symbol (>) with a command, the shell creates the output file immediately, before the command is executed. Demonstrate that this is true. $ ls aaa ls: aaa: No such file or directory $ ls xxxxx > aaa ls: xxxxx: No such file or directory $ ls aaa aaa The first of the preceding commands shows that the file aaa does not exist in the working directory. The next command uses ls to attempt to list a nonexistent file (xxxxx) and sends the standard output to aaa. The ls command fails and sends an error message to standard error (you see it on the screen). Even though the ls command failed, the empty file named aaa exists. Because the ls command failed, it did not create the file; the shell created it before calling ls.

4 Chapter 5 Answers to Exercises 11. In experimenting with shell variables, Alex accidentally deletes his PATH variable. He decides that he does not need the PATH variable. Discuss some of the problems he may soon encounter, and explain the reasons for these problems. How could he easily return PATH to its original value? 12. Assume that your permissions allow you to write to a file but not to delete it. a. Give a command to empty the file without invoking an editor. $ filename < /dev/null or $ cat /dev/null > filename b. Explain how you might have permission to modify a file that you cannot delete. To delete a file, you must have write and execute permission to the directory housing the file. To write to a file, you must have write permission to the file and execute permission to the parent directory. When you have write permission only to a file and execute permission only to the directory the file is in, you can modify, but not delete, the file. 13. If you accidentally create a filename with a nonprinting character, such as a CONTROL character in it, how can you rename the file? 14. Why can the noclobber variable not protect you from overwriting an existing file with cp or mv? The noclobber variable keeps the shell from overwriting a file and does not work on utilities. Thus the noclobber variable keeps a redirect symbol (>) from allowing the shell to overwrite a file (the shell redirects output) but has no affect when you ask cp or mv to overwrite a file. 15. Why do command names and filenames usually not have embedded SPACEs? How would you create a filename containing a SPACE? How would you remove it? (This is a thought exercise, not a recommended practice. If you want to experiment, create and work in a directory with nothing but your experimental file in it.) 16. Create a file named answers and give the following command: $ > answers.0102 < answers cat Explain what the command does and why. What is a more conventional way of expressing this command?

Chapter 5 Answers to Exercises 5 Reading the command line from left to right, it instructs the shell to redirect standard output to answers.0102, redirect standard input to come from answers, and execute the cat utility. More conventionally, the same command is expressed as $ cat answers > answers.0102