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

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

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

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

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.

A shell can be used in one of two ways:

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

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Introduction To. Barry Grant

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Linux Shell Script. J. K. Mandal

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

Files and Directories

bash Scripting Introduction COMP2101 Winter 2019

5/20/2007. Touring Essential Programs

2) clear :- It clears the terminal screen. Syntax :- clear

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

Getting your department account

Using bash. Administrative Shell Scripting COMP2101 Fall 2017

Introduction to Linux

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

Linux & Shell Programming 2014

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

ADVANCED LINUX SYSTEM ADMINISTRATION

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

Introduction of Linux

Chapter-3. Introduction to Unix: Fundamental Commands

5/8/2012. Exploring Utilities Chapter 5

Unix Tools / Command Line

-1- csh cd. cd alias!! ; set prompt=" pwd % " 16 cd. 17 cd.. 18 his /home% set prompt. alias. yasuoka : root :

Essentials for Scientific Computing: Bash Shell Scripting Day 3

The Unix Shell & Shell Scripts

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 2

Computer Systems and Architecture

A Brief Introduction to the Linux Shell for Data Science

Chapter 4. Unix Tutorial. Unix Shell

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.

Introduction to Unix: Fundamental Commands

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Introduction: What is Unix?

Introduction to Linux. Roman Cheplyaka

Recap From Last Time: Setup Checklist BGGN 213. Todays Menu. Introduction to UNIX.

CSCI 2132 Software Development. Lecture 4: Files and Directories

Introduction to the UNIX command line

On successful completion of the course, the students will be able to attain CO: Experiment linked. 2 to 4. 5 to 8. 9 to 12.

d. 1 e. test: $a: integer expression expected

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

Introduction to remote command line Linux. Research Computing Team University of Birmingham

Useful Unix Commands Cheat Sheet

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

CENG 334 Computer Networks. Laboratory I Linux Tutorial

LAB 8 (Aug 4/5) Unix Utilities

Unix Introduction to UNIX

Exploring UNIX: Session 3

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

5/8/2012. Encryption-based Protection. Protection based on Access Permission (Contd) File Security, Setting and Using Permissions Chapter 9

IBM AIX Basic Operations V5.

Shells and Shell Programming

LING 408/508: Computational Techniques for Linguists. Lecture 5

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

Perl and R Scripting for Biologists

Introduction in Unix. Linus Torvalds Ken Thompson & Dennis Ritchie

Introduction to Unix CHAPTER 6. File Systems. Permissions

Shells and Shell Programming

commandname flags arguments

Introduction to Linux

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

18-Sep CSCI 2132 Software Development Lecture 6: Links and Inodes. Faculty of Computer Science, Dalhousie University. Lecture 6 p.

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

Lec 1 add-on: Linux Intro

9.2 Linux Essentials Exam Objectives

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

UNIX Essentials Featuring Solaris 10 Op System

CSE 390a Lecture 2. Exploring Shell Commands, Streams, and Redirection

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

CST8207: GNU/Linux Operating Systems I Lab Six Linux File System Permissions. Linux File System Permissions (modes) - Part 1

UNIX ASSIGNMENT 1 TYBCA (Sem:V)

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

Unix Handouts. Shantanu N Kulkarni

Mills HPC Tutorial Series. Linux Basics I

Lab 2: Linux/Unix shell

Scripting Languages Course 1. Diana Trandabăț

Multiple Choice - 42 Questions - 10 of 20%

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

UNIX files searching, and other interrogation techniques

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Recap From Last Time:

Basic Linux Command Line Interface Guide

Introduction to UNIX I: Command Line 1 / 21

BGGN 213 Working with UNIX Barry Grant

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

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

IMPORTANT: Logging Off LOGGING IN

Basic Linux Command Line Interface Guide

Computer Systems and Architecture

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP

Practical 02. Bash & shell scripting

Practical Session 0 Introduction to Linux

Transcription:

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

Working with Unix 1. Use the on-line manual page to determine the option for cat, which causes nonprintable characters to be displayed. Run the command against /bin/ls (the program file for the ls command). 2. Use the date command to display only the current 'day of the year'. (For example, 201). 3. Perform a keyword search to find all calendar commands. Using the simple calendar program, display the calendar for September 1752. 4. What is the difference between the 'who am i' and 'whoami' commands? 5. Use a suitable command to count the number of lines in /etc/passwd and output the number. Notice that the command also outputs the name of the file, ie: 10 /etc/passwd Can you change your command so that only the number is output? 6. Use a suitable command to count the number of lines in /etc/passwd and output the number. Can you change your command so that only the number is output? 2 / 10 Page 2 of 10

The Unix File System 1. List the content of all directories beginning with 'p' in all subdirectories of /etc using a single ls command. 2. Investigate the -p option on mkdir. Using this, create a directory structure for which the following operations (if executed in sequence) would be valid: cd one/two/three cd../../four cd.././five Remove the above structure using the -rf options on rm. 3. Display the i-node numbers of all files in the root directory. From the output of ls -l how many names does /usr have? What does this indicate? 4. Create two subdirectories, foo and bar. In the first create a file using touch. Use ls -l to determine how many names it has. Create a second name to the same file in foo, and then a third name to the file in bar. Verify that all three names refer to the same file by checking their i-node numbers. Place data into the file using one of its names (redirect the output of some command to it), and cat the file using a different name. Delete the file using its first name. Are the other names still around? What does this tell you about the delete command? Perform the same set of experiments using symbolic links for the second two files. Why is the behavior so different? 3 / 10 Page 3 of 10

Filters and Working with Files 1. Use cat, head and tail to output lines 5 through 7 of /etc/passwd with each line preceded with its line number. 2. Display all but the first 5 lines of /etc/passwd. Display only the last 20 lines of /etc/termcap. 3. Sort the files in root (/) in the following ways (one at a time!). alpha-numerically by file name numerically by file size on the second character of the user name. 4. Cut the permission bits from the output of ls and display only the permissions (no file type or any other stuff). Paste the permissions together so that they appear in four columns. (Ensure that the line containing 'total' is not part of the output!) 5. List the files in the current directory twice (using one ls command ), and using sort and uniq remove the duplicates. List the files in /etc, cut the first 4 characters, and use uniq count duplicates. 6. In the exercise directory is a file called foo. Compare the contents of the file as seen using cat with that seen using an ascii dump. Which characters were invisible to cat? Can cat be persuaded to print them? 7. Investigate the command tr using the online manual. Use tr, uniq, sort and head to analyze the file text and output a list of the ten most popular words in the file. The list should be organized with most popular first and be printed with a count of occurrences. 4 / 10 Page 4 of 10

Permissions 1. Use ls to examine the access permissions of the files and directories in your home directory. What are the permissions for the home directory itself? 2. Create a file called permfile in your unix directory. Use chmod with a numeric argument to change the access permissions of your files as follows: ---------- README -rw-rw-rw- gen -r--r--r-- pubs -rwxrwxrwx permfile Verify that these permissions are correct using ls.sort the files in root (/) in the following ways (one at a time!). 3. What happens when you attempt to cat README? What happens when you attempt to execute the program gen? 4. Use the chmod command with a symbolic argument to enable only the owner of README to read the contents and to enable any user to execute gen. Verify these changes, and then remember to kill gen if it is running in the background. 5. Create a new directory and file called 'adir' and 'afile' and examine their default permissions. Determine the current value of the umask. How does umask relate to the permissions---and why are files different to directories? 6. Change the value in umask so that read permission is not granted by default to all users. Create some files and use ls to verify that the file permissions are correct. 5 / 10 Page 5 of 10

Editors 1. Use ed to create a new file containing a few lines. Write the file and quit. 2. Use ed to edit IChing. Add three lines to the file: one before the first line, one in the middle and one after the last. Save the result in hack. 3. Use ed to edit README. Substitute all occurrences of the for THE (including multiple occurrences per line). Quit the editor without saving the changes. 4. Use ed to edit README. Delete all lines that end with a full stop. Copy the first 10 lines to the end of the file. Save the changes in README3. 5. Apply the edits suggested for ed to README and IChing using vi. 6 / 10 Page 6 of 10

The Shell 1. Type * and press return. What happened? Try typing echo * and see what happens. 2. Use the touch command once to create five files with the following filenames: Hello World -t $MYFILE \file\.one. List each of these files to make sure that they are all there, both as a group, and individually. Delete each of the files individually.. 3. Attempt to cat two files, one that does exist and one that does not. Next, redirect the valid output to a file called 'data' and any error messages to a file called 'error'. Verify this worked. Finally, redirect both the error and normal output into a pipeline and count the number of lines.. 4. Create a new shell variable called me, and assign it your name as its value, for example: me="joe Bloggs" Do NOT export the variable. Start a new shell from the command line. You will only need to type the name of the shell, for example: bash What value is contained in the shell variable me now? Exit the shell that you have just created,. What is the value of the me shell variable now? Export the variable, and start another shell. What has happened now? Change the value of the variable, and export it again. Exit the child shell. What has happened to the value of the variable in the parent shell? 7 / 10 Page 7 of 10

Basic Shell Programming 1. Write a shell script with 5 commands in it, such as ls, date, ps, who and a cd command, changing directory to /tmp Make sure that the script has been made executable. After the script has completed, which directory is your shell in? Modify your script so that you can verify that the cd command has taken place 2. Write a script called integer.sh so that it will handle 2 variables. Each of these variables will be numbers. The output of the script should show the results of each of the integer arithmetic operations when applied to the variables that you have supplied on the command line, for example, for a script called integer: $./integer.sh 10 5 10 + 5 = 15 10. 5 = 5 10 * 5 = 50 10 / 5 = 2 What happens if you do not type in numeric values? 3. Write a shell script called del.sh, which will accept a filename as a parameter. It must then test whether the file exists. If the file exists, the script should then verify that file could be deleted. If it can be deleted, then the script should delete it. If the file does not exist, or the process does not have the permissions to delete the file, then an appropriate message should be given to the user.. 4. Write a shell script that will inspect a file, which is to be specified as a parameter to the script. The script should print the file name, and then details about the file, where only the tests on the file prove successful. Example output may be: file1: is readable is writeable is executable is a symbolic link 5. Rewrite your answer to Question 4, so that instead of passing the file name as a parameter into the script, the user is prompted to enter a filename, which is then read by the script.. 8 / 10 Page 8 of 10

Power Tools sed and awk 1. Generate a long listing of the /bin directory. Use sed to process the output from the listing as follows: Display the top 10 files in terms of the file size. Generate output in the following formats: Ordered by file size, for example: afile 1234567 bigfile 123455 another 123446 alastfile 3456... Ordered by file name, for example: afile 1234567 alastfile 3456 another 123446 bigfile 123455... Perform all of these tasks without using any intermediate files 2. Repeat question 1, using awk instead of sed. 9 / 10 Page 9 of 10

Advanced Shell Programming 1. Write a shell script, which will behave as a text based file manager. The script should provide the user with a list of options, including a quit option to be able to exit from the script. Options that the script may provide include: Listing the files in the current directory - if the file list is longer than one screen full, the user should able to view the list of file names one screen at a time. The user should also be able to do a long listing of the files in the directory (perhaps by using a sub-menu screen). Change to another directory. Create new files in the current directory. Delete files in the current directory. Edit a file in the current directory (but only if it is a regular file). Move files from one directory to another. Any other applicable operations. No error messages from STDERR should be displayed to the user; all events and appropriate files should be tested before they are executed. Make use of the clear command to blank and reset the terminal window before printing anything out, such as the menu screen. There should always be a line somewhere on the menu, which informs the user as to which is the current directory. Try and utilize functions where possible. 10 / 10 Page 10 of 10