CST8177 Midterm 1 010 - 11W Answers. Question 1 (10 marks) User clarke (home directory /home/clarke) has two directories in ~, ready and done, where he.

Slides:



Advertisements
Similar presentations
การใช้ระบบปฏิบัติการ UNIX พื้นฐาน บทที่ 4 File Manipulation วิบูลย์ วราสิทธิชัย นักวิชาการคอมพิวเตอร์ ศูนย์คอมพิวเตอร์ ม. สงขลานครินทร์ เวอร์ชั่น 1 วันที่
Advertisements

1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Josh Goodwin
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
Links Learning Objectives: 1. To understand the basics of links & its usage 2. To learn the construction / removal of different types of links 3. To distinguish.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
Guide To UNIX Using Linux Third Edition
Links Software Tools. Lecture 4 / Slide 2 Links l A link is a pointer to a file. l In fact, in UNIX all filenames are just links to a file. Most files.
Introduction to Unix – CS 21 Lecture 5. Lecture Overview Lab Review Useful commands that will illustrate today’s lecture Streams of input and output File.
Introduction to Linux and Shell Scripting Jacob Chan.
Shell Script Examples.
Chapter 4: UNIX File Processing Input and Output.
MCB Lecture #3 Sept 2/14 Intro to UNIX terminal.
1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID COSC 513 Operating System.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Working with Files Chapter 5. Display a Calendar Display a calendar for a specific month – cal Display a calendar for a specific year – cal 2000.
3 File Processing Mauro Jaskelioff. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Agenda Basic Shell Operations Standard Input / Output / Error Redirection of Standard Input / Output / Error ( >, >>,
Guide To UNIX Using Linux Fourth Edition
BIF703 stdin, stdout, stderr Redirection. stdin, stdout, stderr Recall the Unix philosophy “do one thing well”. Unix has over one thousand commands (utilities)
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 8 Shell.
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.
Day 2 Review of ITSK1601 – Intro Unix.. Break up into Cousin groups Each cousin group will work as a team. Each team will need 5 blank sheets of paper.
Linux+ Guide to Linux Certification, Third Edition
Guide to Linux Installation and Administration, 2e1 Chapter 7 The Role of the System Administrator.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Lesson 9-Setting and Using Permissions. Overview Describing file permissions. Using execute permissions with a file. Changing file permissions using mnemonics.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
Quiz 15 minutes Open note, open book, open computer Finding the answer – working to get it – is what helps you learn I don’t care how you find the answer,
BIF703 Hard & Symbolic Links. What is a file system Link? A link is a pointer to a file. This pointer associates a file name with a number called an i-node.
Pipes and Redirection in Linux ASFA Programming III C. Yarbrough.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
I/O and Redirection. Standard I/O u Standard Output (stdout) –default place to which programs write u Standard Input (stdin) –default place from which.
Managing Files. Module 5 Managing Files ♦ Introduction “On a Linux system, everything is a file; if something is not a file, it is a process.” ♦ Topics.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CSCI 330 UNIX and Network Programming Unit IV Shell, Part 2.
CSCI 330 UNIX and Network Programming Unit IV Shell, Part 2.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
Sed. Class Issues vSphere Issues – root only until lab 3.
Files and Directories in UNIX The first file in UNIX file system is “root” or “/”
Command Prompt Chapter 9 Pipes, Filters, and Redirection ©Richard Goldman 11/30/2000 Revised 10/16/2001.
The Unix File System R Bigelow. The UNIX File System The file system refers to the way in which UNIX implements files and directories. The UNIX file system.
1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Jessica Miller & Ruth Anderson
Basic UNIX system administration CS 2204 Class meeting 14 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Unix Lab Fall Shell Scripting ●Through the shell (LXTerminal) you can: ●Run programs. ●Interact with the file system. ●Change settings. ●Send/receive.
Using Crontab with Ubuntu
Exploring Shell Commands, Streams, and Redirection
Prepared by: Eng. Maryam Adel Abdel-Hady
System Administration
stdin, stdout, stderr Redirection
Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, and Redirection
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, and Redirection
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, and Redirection
Presented by, Mr. Satish Pise
A shell is a user interface.
Exploring Shell Commands, Streams, and Redirection
Presentation transcript:

CST8177 Midterm W Answers

Question 1 (10 marks) User clarke (home directory /home/clarke) has two directories in ~, ready and done, where he does his testing. He has a script named pgm-1 that he is testing in first-level (alpha) testing, and another named pgm-2 in second-level (beta) testing. They are stored in the appropriate directories, pgm-1 in ready and pgm-2 in done. Therefore, the directory structure looks like this: [diagram deleted] In directory ready, create a hard link to pgm-2 in done, and in directory done, create a soft link to pgm-1 in ready. Note: You must use relative paths throughout, you may not use the cd command, and your present working directory is /home/clarke. List your commands here: clarke]$ ln done/pgm-2 ready/h-pgm-2 clarke]$ ln -s../ready/pgm-1 done/s-pgm-1

Displaying the result (not required) :./done: rw-rw-r--. 2 pgm lrwxrwxrwx. 1 s-pgm-1 ->../ready/pgm-1./ready: rw-rw-r--. 2 h-pgm rw-rw-r--. 1 pgm-1 User/group and date/time removed for clarity. Note that done/pgm- 2 and ready/h-pgm-2 have link counts of 2, and both use inode

Question 2 (20 marks) The file gray contains the following text: 1:I must say a few words in this place about "Old Gray." Why he 2:was always called "Old Gray" is more than I know. His colour 3:could not have suggested the name, for he was a bright roan, 4:almost a bay. He was by no means a pretty animal, being raw- 5:boned, and never seeming to be in first-rate condition; but he 6:was endowed with remarkable sagacity and great endurance, and 7:was, moreover, a fleet trotter. It is part of a paragraph taken from The Project Gutenberg EBook of Life in Canada Fifty Years Ago, by Canniff Haight ( ). Use the line numbers (just count them, 1 to last) in answering the following questions about grep and regular expressions:

a) Use grep -c to determine the number of lines: grep command:grep -c '.' gray Result on stdout:7 b) Which lines start with a capital (upper-case) letter? grep command:grep -n '^[A-Z]' gray Lines on stdout:1 c) Find all the lines with the word "Gray" or "gray"; use 2 different methods:: grep command 1:grep -n '[Gg]ray' gray grep command 2:grep -in 'gray' gray Lines on stdout:1, 2 d) Several lines begin with the letters "was"; find them: grep command:grep -n '^was' gray Lines on stdout:2, 6, 7

e) Several lines end with comma, period, or dash (',', '.', or '-'). Find them: grep command:grep -n '[[:punct:]]$' gray Alternate grep:grep -n '[,.-]$' gray Lines on stdout:3, 4, 7 f) If you knew that each and every sentence ends with a dot (period; full-stop) '.', that no line contains 2 sentences, and that there was no other use of the dot, what grep command would you use to count the number of sentences: grep command:grep -c '\.' gray How many sentences:4

Question 3 (5 marks) You recall that there are several cron-related directories in /etc but you have forgotten the names. Looking up the find command, you learn that -type d will select only directories, and you remember the -name keyword all by yourself. Write the find command that you will use to display all directories (there is more that one) with cron somewhere in their name (you are logged-in as root): find /etc -name '*cron*' -type d The result (not required): /etc/cron.monthly /etc/cron.d /etc/cron.weekly /etc/cron.daily /etc/cron.hourly

Question 4 (10 marks) You are in the directory dir1 (~/dir1) as user asimov. The directory has only one file named my-file with the contents "this is my file" followed by a newline character (ENTER). The file is therefore 16 bytes in size. Put the redirection needed to the right of the command, and show the output on the screen from each command below. Assume the commands are run in sequence. That is, a command will change the situation for all subsequent commands. Show any error messages as your best approximation; it doesn't have to be the exact text. a) Do not make any changes:cat my-file this is my file b) Do not make any changes:cat missing cat: missing: No such file or directory

c) Redirect stderr to the new file file-a: ls my-file missing 2> file-a my-file d. Do not make any changes:cat file-a ls: cannot access missing: No such file or directory d. Append stdout to file-a: ls my-file missing>> file-a ls: cannot access missing: No such file or directory d. Do not make any changes:cat file-a ls: cannot access missing: No such file or directory my-file

g. Redirect stdout to the new file file-b: ls my-file missing> file-b ls: cannot access missing: No such file or directory g. Do not make any changes:cat file-b my-file g. Append stderr to file-b ls my-file missing2>> file-b my-file g. Do not make any changes:cat file-b my-file ls: cannot access missing: No such file or directory

Question 5 (5 marks) You require a crontab file that will run the backup script from /home/share/bin every Monday at 4:05 in the morning, sending the output for your review to a file called backup.run in your home directory. You are logged in as arthur. You recall that, except for Day-of-Week (which is last), the time elements in the crontab entry are in increasing order. You do not at present have a crontab so you first create the file ~/crontab.arthur. a) List the content of your user crontab file: # min hr dom mon dow command 5 4 * * 1 /home/share/bin/backup > /home/arthur/backup.run b) Show the command you will use to add your file to cron's list: crontab ~/crontab.arthur