Appendix B WORKSHOP. SYS-ED/ Computer Education Techniques, Inc.

Similar documents
Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

UNIX Shell Programming

Set 1 MCQ Which command is used to sort the lines of data in a file in reverse order A) sort B) sh C) st D) sort -r

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

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

UNIX Essentials Featuring Solaris 10 Op System

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

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

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

Oxford University Computing Services. Getting Started with Unix

IBM AIX Basic Operations V5.

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

CST Algonquin College 2

INSE Lab 1 Introduction to UNIX Fall 2017

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

The Directory Structure

CSCI 2132 Software Development. Lecture 4: Files and Directories

Unix Introduction to UNIX

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

Introduction to Linux Workshop 1

Outline. Structure of a UNIX command

Part 1: Basic Commands/U3li3es

Introduction of Linux

Scripting Languages Course 1. Diana Trandabăț

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.

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

5/20/2007. Touring Essential Programs

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

ACS Unix (Winter Term, ) Page 92

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one]

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

Unix File System. Learning command-line navigation of the file system is essential for efficient system usage

UNIX Basics. Science & Technology Support Group High Performance Computing Ohio Supercomputer Center 1224 Kinnear Road Columbus, OH 43212

Operating Systems. Copyleft 2005, Binnur Kurt

Useful Unix Commands Cheat Sheet

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

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

Introduction to the UNIX command line

The Unix Shell & Shell Scripts

Chapter-3. Introduction to Unix: Fundamental Commands

This is Lab Worksheet 3 - not an Assignment

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

Unix System Architecture, File System, and Shell Commands

Introduction to UNIX Shell Exercises

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

Course 144 Supplementary Materials. UNIX Fundamentals

Lab 2: Linux/Unix shell

UNIX Quick Reference

UNIX Quick Reference

CS4350 Unix Programming. Outline

h/w m/c Kernel shell Application s/w user

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

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

CSCE 212H, Spring 2008, Matthews Lab Assignment 1: Representation of Integers Assigned: January 17 Due: January 22

5/8/2012. Creating and Changing Directories Chapter 7

Chapter 1. Getting started with UNIX

Basic Linux (Bash) Commands

Std: XI CHAPTER-3 LINUX

Physics REU Unix Tutorial

Linux Command Line Interface. December 27, 2017

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

Computer Systems and Architecture

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

Introduction to Unix and Linux. Workshop 1: Directories and Files

commandname flags arguments

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

Mills HPC Tutorial Series. Linux Basics I

Computer Systems and Architecture

Part I. Introduction to Linux

CENG 334 Computer Networks. Laboratory I Linux Tutorial

PDS Lab Section 16 Autumn Tutorial 1. Unix Commands pwd The pwd command displays the full pathname of the current directory.

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2)

CS 25200: Systems Programming. Lecture 11: *nix Commands and Shell Internals

Week Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages

Perl and R Scripting for Biologists

The Shell. EOAS Software Carpentry Workshop. September 20th, 2016

Introduction to Linux Environment. Yun-Wen Chen

CS 460 Linux Tutorial

Introduction to Linux Part 1. Anita Orendt and Wim Cardoen Center for High Performance Computing 24 May 2017

Introduction to Supercomputing

Introduction to Linux. Roman Cheplyaka

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

UNIX Command Cheat Sheets

Unix Filesystem. January 26 th, 2004 Class Meeting 2

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

Files and Directories

Introduction to Linux

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

Unix Handouts. Shantanu N Kulkarni

System Programming. Introduction to Unix

UNIX Command Cheat Sheets

UNIX Basics. UNIX Basics CIS 218 Oakton Community College

Refresher workshop in programming for polytechnic graduates General Java Program Compilation Guide

This section reviews UNIX file, directory, and system commands, and is organized as follows:

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 tutorial. Thanks to Michael Wood-Vasey (UPitt) and Beth Willman (Haverford) for providing Unix tutorials on which this is based.

Getting started with Hugs on Linux

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

Introduction: What is Unix?

Software I: Utilities and Internals. What is UNIX?

Transcription:

Appendix B WORKSHOP SYS-ED/ Computer Education Techniques, Inc.

1 Introduction There are no workshops for this chapter. The instructor will provide demonstrations and examples. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 1

2 Commands and Utilities 1. Execute the following commands; they require no arguments or options: Date Whoami Who W pwd Clear Show date and time Show your userid Show who is logged onto the system. Show who is logged onto the system. Print the working directory's name. Clear the screen. 2. Execute the following commands; they require arguments and/or options: ls a ls al cat.cshrc Mkdir dir1 cd dir1 cd Rmdir dir1 cp.login new.login wc new.login wc -l new.login rm new.login List all files in current directory. Long list of current directory. Display contents of.cshrc file. Make a directory called dir1 Change directory to dir1. Change to parent directory. Remove directory dir1 Copy the.login file to new.login. Count the lines, words and characters in the new.login file. Count just the lines. Remove the new.login file. 3. Use multiple commands on one line; this is done by including the semi-colon between commands. cp.login testfile ; cat testfile - copy a file and then show its contents ls -l testfile ; rm testfile ; ls -l testfile - list (long) a file, remove it, and then try to list it again SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 2

4. This exercise will provide familiarity with several UNIX special characters. Use the "*" wildcard character to list all of the files in the present working directory: ls * Use the "?" wildcard character, to list all files with 3 character names: ls??? Use square brackets and wildcard characters in order to list files several different ways: ls [a-c]* ls [abcde]* ls [a-z]* ls [z]* ls??[c]* ls?[e]* Use the right angle bracket ">" and the semi-colon ";", to concatenate three files into a single new file and then display it: cat alpha beta gamma > newfile ; cat newfile SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 3

3 Files and Directories Create a Home Directory Structure Use the following commands: Mkdir Rmdir Rm Ls Pwd Cp Cd Make a directory. Remove a directory. Remove a file. List files and directories. Print working directory. Copy files and directories. Change directory. Example: mkdir temp rmdir temp ls, ls -al cd cd / cd /usr/local/bin cd temp cp /etc/profile. 1. Regardless as to the current location in the filesystem hierarchy, go to the "home" directory. 2. In the home directory, create the following subdirectories: documents spreadsheets employees 3. Within the "documents" subdirectory, create the following subdirectories: letters memos 4. Within the "spreadsheets" directory, create the following subdirectories: plans budget proposals 5. Move into the "budget" directory. What is the current "path"? 6. Move back to the "home" directory. Copy the file named "/usr/fred/.exrc" to the home directory. This file will be needed for later exercises with the "vi" editor. 7. In the home directory, create a long list of all the files. Which of these "files" are actually directories? How easy is it to tell which files are directories? SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 4

4 UNIX Commands Perform the following file management exercises. 1. What are the current permissions for the home directory? What permissions do users in your group have in your home directory? What permissions do users not in your group have in your directory? 2. "cat" out your.profile; this is done by using the cat command to display the.profile file on the computer screen. 3. Make a backup copy of your.profile file. Name the backup copy.profile.bak. 4. In the Korn shell, there are two startup files: "/etc/profile" ".profile", which is located in the home directory. Use the wc command, in order to determine how many lines are contained in each of the following files. File Name /etc/profile.profile Number of lines 5. Assume that you have been promoted to Sales Manager of a small business in Louisville, Kentucky. Make a directory in your home directory called vendors: /home/stu#/vendors Make other directories in your home directory called clients, proposals, and misc. 6. Move in to the clients directory. Create a directory called ky; this stands for Kentucky. Create another directory and call it Indiana. 7. Move in to the ky directory. What is the current working directory/full path? 8. The previous Sales Manager was named "Fred". Copy all of the files from /home/fred/clients/ky to the ky directory. Confirm that all of the files have been copied properly. 9. Move into another student's directory and try to create a file there with the "touch" command. What happens? Why? SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 5

10. Move to different directories on the Unix file system and try using the file command to ascertain which different types of files are on the system. What types of files are in the /bin or /dev directories? 11. Copy the /etc/passwd file to your home directory. Confirm that it is there. From the home directory delete the passwd file that was created in the misc sub-directory. 12. Use the df command with the -k option to ascertain how full the "/" and "/stand" filesystems are. What is the capacity and available space. 13. Use the find command to search for files named lpsched file in the /usr directory system. 14. Use the find command to locate all of the files on the system that have been modified within the last two days. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 6

5 vi Text Editor Perform this cursor movement exercise: 1. Create a new file using vi. 2. Enter a few short paragraphs. 3. Use the cursor positioning keys, scroll up, down, left and right. 4. Use the Scrolling and paging commands to scroll up and down a page. Scroll up and down; one line at a time. 5. Search for the letter a. Find the next occurrence of the letter a. 6. Search backwards for the letter a. Find the previous occurrence of the letter a. 7. Move the cursor to the 20 th line in the file. Move to the first line. Move to the last line. Use the G command. 8. Display the state of the file. 9. Move the cursor to the top line on the screen. 10. Move the cursor to the middle line on the screen. 11. Move the cursor to the last line on the screen. 12. Move the cursor forward 1 word. 13. Move the cursor backward 1 word. 14. Move the cursor to the end of the current word. 15. Save the file. Terminate vi. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 7

Perform this string handling exercise: 1. Find any word and insert an s at the end of the word. 2. Insert a blank line before an existing line. 3. Delete a single character. 4. Replace a single character. 5. Replace a single character with several characters. 6. Delete a word. 7. Delete the previous word. 8. Change the text of a single word. 9. Delete a line. 10. Replace a single line. 11. Delete all line from the cursor to the end of the file. 12. Undo the previous command. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 8

6 Execution Environment Processes and Job Control Exercise 1. Display the current processes with the "ps -f" command. What processes are running? 2. What is the PID of the "ksh" process? 3. What happen if the PID of the "ksh" process is killed? 4. Use the "ps" command to determine what processes are being used by user "stu1". 5. Use the following command for purpose of determining how many processes are being run by student accounts: ps -ef grep stu wc l 6. Use the "-u" option with "ps" to determine what processes are being run by Student #1. 7. Try to kill the PID of Student #1's "ksh" process. What happens? SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 9

Multi-Processing Type the following commands: Type Description Cd Move to your home directory. vi.profile Edit your.profile file. ^Z Suspend your vi job. vi /etc/profile Edit the /etc/profile file ^Z Suspend that vi job. Jobs l List the jobs in your job table. Find /usr -name lpsched - print Search for a file named lpsched. ^Z Stop the find command. Jobs l List the jobs in your job table again. systat Run a shell program named systat. ^Z Suspend that process also. fg %1 Go back to your first vi process - your.profile file. :q Quit vi Jobs l List the jobs in your job table again. fg %2 Bring your second vi editing session back to the foreground. :q Quit this vi session also. Jobs l List the jobs again. fg Bring the most recent job to the foreground. q Quit the systat program. fg Bring the "find" process back to life in the foreground. ^i Interrupt the find searching process. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 10

7 Shell Programming Write a shell script which renames all.txt files as.text files. Write a shell script called pidof which takes a name as parameter and returns the PID(s) of processes with that name. Shell scripts can also include functions. Functions are declared as: function funcname() { statements } and invoked as funcname param1 param2... The parameters passed to the function are accessible inside the function through the variables $1, $2, etc. Add a usage() function to the pidof script which prints usage instructions. Call usage() if the wrong number of parameters is passed to the script. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 11

8 Bourne Shell Programming 1. Write a script called greetme that: Greets the user. Prints the date and time. Prints the name of your machine. 2. Write a script called rename that will take two arguments: the name of the original file and the new name for the file. If two arguments have not been entered, print an error message and exit. Otherwise, rename the file and print a message stating what has been done. 3. Modify the previous program to check for the existence of the original file before attempting to rename. If it exists, rename it. Otherwise print an appropriate error message. 4. Write a script called userinfo that:: Asks the user's full name: first middle and last. Greets the user by name and ask for the year when born. Calculate their age and output it to the screen with an appropriate message. 5. Write a script called checking that will: Take as a command line argument the user's name. Test whether the argument was provided and exited with an appropriate message. If the argument was not provided with an appropriate message; check whether the user is in /etc/passwd. If the argument was not provided with an appropriate message, print a message stating that the user was found or there was "no such user on our system." SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 12

Perform the following Korn Shell" exercises: 9 Korn Shell Programming 1. Change the prompt (PS1) to display the current working directory. 2. Change the second prompt to read "continue, master: ". 3. What is the value of the TERM and HOME environment variables? 4. What is the value of your PATH variable? Write this down. Now modify your PATH variable to only include the /usr/local directory. Try the date command again - what happens? Try the ls command. Then try the pwd and the cd commands. 5. Log out and back in, then use the whence command to see if you can find out what happened. 6. Set the noclobber variable (enable it). Create a file named file_list by redirecting the standard output from an ls command. Then, try to overwrite this file by performing the exact same command again. What happens? 7. Create an alias named dir that you can use that stands for the following pipeline command: ls -af more 8. Create an alias named where that stands for pwd. 9. Create an alias named del that stands for "rm -i". 10. What is the value of your HISTSIZE variable? SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 13

11. Enter the following commands: cd ls ls -al ps -ef who 12. Use the fc -l command to list your previous commands. 13. Use the r command to repeat your most recent ls command, referring to the ls command by number. 14. Use the r command to repeat your most recent ps command, referring to the ps command by name instead of by number. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 14

10 sed Answer the following questions. 1. What will the command sed ' ' filename do? 2. Where does sed normally place its output? 3. What will the command sed '2,4 s/e/#/ ' filename do? 4. What will the command sed '2,4 s/e/#/g ' filename do? 5. What will the command sed '2,end s/e/#/ ' filename do? 6. What does the metacharacter.o match? 7. What does the metacharacter $ do? 8. What does the pattern '^.o' match? 9. What is the difference between: sed '/^$/d' filename and sed '/^ *$/d' filename do? 10. How does the option -n change a sed instruction? 11. Enter a sed command that will place 10 spaces at the beginning of each line of file1. 12. What does the command sed '5q' file1 do? 13. What does the command sed '/west/s/5/8' file1 do? 14. What does the sed command sed -e '1,3d' -e 's/hemenway/jones/' datafile do? 15. What does the sed command sed -n '/west/,/east/p' datafile do? SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 15

11 awk Programming Answer the following questions. 1. What do the escape characters do in awk statements? 2. What is the purpose of format specifiers in printf statements? 3. What are some differences between print and printf in awk? 4. When multiple actions are entered in a awk command, how is this different from entering a single line command versus a multi-line script? 5. Explain the way the tilde (~) command works in awk? 6. What is the role of a pattern versus an action in awk? 7. What do the following regular expression metacharacters do in awk? 8. Discuss the -F option in awk as it relates to multiple field separators. 9. What does the variable $0 contain in awk? 10. What does the command awk '{print $0}' datafile do? SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 16

Use the file provided by the instructor and perform the following: 1. Enter the awk command that will print all the phone numbers. 2. Enter the awk command that will print Dan's phone number. 3. Enter the awk command that will print Susan's name and phone number. 4. Enter the awk command that will print all last names beginning with D. 5. Enter the awk command that will print all first names beginning with C or E. 6. Enter the awk command that will print all first names containing only four characters. 7. Enter the awk command that will print the first names of all those in the 916 area code 8. Enter the awk command that will print Mike's campaign contributions preceded by a dollar sign ($) 9. Enter the awk command that will print last names followed by a comma followed by the first name (easier than with sed). 10. Write a awk script called facts that: Prints full names and phone numbers for the Savages. Prints Chet's contributions. Prints all those who contributed $250 the first month. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (UNIX-for App Dev - 4.12) App B: Page 17