COL100 Lab 2. I semester Week 2, Open the web-browser and visit the page and visit the COL100 course page.

Similar documents
Laboratory 1 Semester 1 11/12

COMP s1 Lecture 1

CS 460 Linux Tutorial

Introduction to Linux

Practical Session 0 Introduction to Linux

Overview. Unix/Regex Lab. 1. Setup & Unix review. 2. Count words in a text. 3. Sort a list of words in various ways. 4.

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

Introduction to the shell Part II

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

Exercise 1: Basic Tools

CSE 351. Introduction & Course Tools

Unix Tools / Command Line

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

Introduction to Linux

Lab 1 Introduction to UNIX and C

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Problem Set 1: Unix Commands 1

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

Systems Programming and Computer Architecture ( ) Exercise Session 01 Data Lab

Introduction to Supercomputing

CSC 2500: Unix Lab Fall 2016

Week 5 Lesson 5 02/28/18

Hand-on Labs for Chapter 1 and Appendix A CSCE 212 Introduction to Computer Architecture, Spring

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Intermediate Programming, Spring Misha Kazhdan

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

Unix L555. Dept. of Linguistics, Indiana University Fall Unix. Unix. Directories. Files. Useful Commands. Permissions. tar.

The Unix Shell & Shell Scripts

Getting started with UNIX/Linux for G51PRG and G51CSA

Chapter-3. Introduction to Unix: Fundamental Commands

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

Introduction To Linux. Rob Thomas - ACRC


CS Operating Systems Lab 3: UNIX Processes

Introduction to Unix

Unix Tutorial Haverford Astronomy 2014/2015

Introduction to Linux. Roman Cheplyaka

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.

CSC111 Computer Science II

Carnegie Mellon. Linux Boot Camp. Jack, Matthew, Nishad, Stanley 6 Sep 2016

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.

EKT332 COMPUTER NETWORK

1. Open VirtualBox and start your linux VM. Boot the machine and log in with the user account you created in Lab #1. Open the Terminal application.

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

Recitation #1 Boot Camp. August 30th, 2016

Introduction to Linux

LOG ON TO LINUX AND LOG OFF

A Brief Introduction to the Linux Shell for Data Science

Introduction To. Barry Grant

Perl and R Scripting for Biologists

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

Introduction To. Barry Grant

Recitation #1 Unix Boot Camp. August 29th, 2017

5/8/2012. Exploring Utilities Chapter 5

Bash Programming for Geophysicists

Lab 1 Introduction to UNIX and C

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

Linux Text Utilities 101 for S/390 Wizards SHARE Session 9220/5522

6.033 Computer System Engineering

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

Introduction to Linux


List of Linux Commands in an IPm

Unix Basics. Benjamin S. Skrainka University College London. July 17, 2010

CS356: Discussion #1 Development Environment. Marco Paolieri

CSE 374 Midterm Exam 2/6/17 Sample Solution. Question 1. (12 points, 4 each) Suppose we have the following files and directories:

Introduction to UNIX command-line

CSE 303 Midterm Exam

Introduction to Scripting using bash

commands exercises Linux System Administration and IP Services AfNOG 2015 Linux Commands # Notes

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

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

Linux Exercise. pwd answer: We call this directory (into which you get when you log in) your home directory.

1 Installation (briefly)

CS 253: Intro to Systems Programming 1/21

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

CSC UNIX System, Spring 2015

Commands are in black

Introduction. File System. Note. Achtung!

Recap From Last Time:

BGGN 213 Working with UNIX Barry Grant

CSE 374 Midterm Exam Sample Solution 2/6/12

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

LAB 1 INTRODUCTION TO LINUX ENVIRONMENT AND C COMPILER

Name: Peter Lemieszewski Venue: Education

CSC209. Software Tools and Systems Programming.

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

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

Unix Basics. Systems Programming Concepts

Open up a terminal, make sure you are in your home directory, and run the command.

CSC209. Software Tools and Systems Programming.

Parallel Programming Pre-Assignment. Setting up the Software Environment

Introduction to Unix: Fundamental Commands

Contents. xxvii. Preface

CS197U: A Hands on Introduction to Unix

INSE Lab 1 Introduction to UNIX Fall 2017

Week 1: Linux Intro. The Command Line Interface

Operating Systems. Copyleft 2005, Binnur Kurt

mkdir Phys338 s2017 Draw the tree of the directories and files for this step and all the following cd Phys338 s2017

Transcription:

COL100 Lab 2 I semester 2017-18 Week 2, 2017 Objective More familiarisation with Linux and its standard commands Part 1 1. Login to your system and open a terminal window. 2. Open the web-browser and visit the page https://moodle.iitd.ac.in and visit the COL100 course page. Go to the news forum and from there visit the COL100 course home page From the course home page, visit the link to Piazza for course discussions. Create a Piazza account and sign-up for the course at Piazza. 3. In this exercise we will learn about the less command which is very similar to the more command with more features. If you have a file, then the simplest method to view its content will be using the cat command. The cat command concatenates the contents of all the files given in its command line and prints the results to its standard output, i.e., your terminal window. Type the following command: ls /bin > bin_dir.txt Recall that if a command is followed by a > sign and then by a filename then the standard output of the command is sent to the file instead of being displayed on the terminal. In the above command the standard output of the ls command it sent to the file bin_dir.txt in your current directory. Use the ls command to check that the file bin_dir.txt has been created and then run the following commands cat bin_dir.txt The contents of the file were too much to see in a terminal window. They would have scrolled past. Type man cat to learn more about cat. To see contents of big files we use more and less commands. In this session we will experiment with the less command. You are already familiar with the man command. To get complete details of more or less commands, you may use the man command (which in-turn uses the less command to display the manual pages). Now run the following

command and while the command is active, experiment by pressing the following keys SPACE BAR, f, b, q. less bin_dir.txt What do these keys do when the less command is active? To search forward for a pattern, type / followed by pattern. To search backwards for a pattern, type? followed by pattern. So to for look for the string zip in the file bin_dir.txt, type /zip when less is active. Do the following to illustrate this run the following commands: less bin_dir.txt (and without pressing the q, type /zip. What do you see? Press the n and N keys to find the next and the previous matches. Also experiment with typing?zip and then the keys n, N to move forward and back. Finally type q to quit). We will now use the man command and search in the man pages. Type the following command to get the manual page on the less command. man less (Now type /COMMAND to reach to the command section directly and use SPACE and b key to scroll forward and back). Instead of reading the complete manual pages, you can use the search facility to directly get to the topics you are interested in. Now open your web browser and go to www.google.com, and type the following on the google search bar and follow the links to get more information on the less command how to use less command in linux 4. Now we will experiment with the find command which is used to find specific files and directories in the file system. If you have not yet finished the previous lab assignment, please do so now. In the previous lab assignment, you would have experimented with the find command. Now use the find command to find all the files with names containing the string zip. How many files are there in the /bin directory with the name containing the string zip. If you haven t figured this out, the command to do this is given below find /bin name *zip* -print How many such files are in the /usr/bin directory? Now you can place the * appropriately to answer the following questions: How many files in the /usr/bin directory are there with names starting with zip? How many files in the /usr/bin directory are there with names ending with zip? 5. Now we will experiment with the grep command which is used to print all lines in a file that contain a given pattern. Type the following command grep zip bin_dir.txt

This command will print all the lines in the file bin_dir.txt that contain the string zip. Since the file bin_dir.txt was the output of the ls /bin command, you should get names of the all the files in the /bin directory that contain the pattern zip. Now look at the man page of grep and search for word (remember how to search while less command is active) and read the section explaining the w option. Now experiment with the w option of the grep command by running the following commands: grep w zip bin_dir.txt grep w gzip bin_dir.txt The above commands can be run directly without storing the results in the intermediate files using the pipe construct. Without running the commands, write down what you think they will output. ls /bin grep zip ls /bin grep w zip ls /bin grep w gzip ls /usr/bin grep zip ls /usr/bin grep w zip ls /usr/bin grep w gzip Now run the above commands and compare your results. Visit google.com on your browser and type the following to get more help on grep command: How to use grep command in linux 6. Now we will experiment with the wc (word count) command. output Read the manual page of wc. Now type the following and carefully observe and explain the wc bin_dir.txt Construct a single command to count the number of files in /bin directory using the commands ls and wc commands and pipes. Modify your command to count the number of files in the /usr/bin directory. Construct commands to count the number of files in /bin and /usr/bin directories whose names contain the letter a, using the commands ls, grep and wc commands and pipes 7. Now we will explore the sort command which is used to sort the lines in a given file. Read the manual page of the sort command. Construct a command to print the files in /bin directory in descending sorted order (filenames starting with z should come first followed by those starting with y and so on). ls /bin sort r less

Now view the contents of /usr/bin directory in the descending sorted order. 8. The tr (translate) command can be used to replace one set of characters with another. To replace a with e you may type tr a e <filename>. By default tr reads standard input and carries out the translation and prints the results to standard output. Fun exercise: for converting all the a s into e s in the manual page of tr type the following command man tr tr a e less To convert a to e, e to i, i to o, o to u and u to a use the following: man tr tr aeiou eioua less Rest is up to your imagination and creativity. Part 2 1. Use the gedit command to create a file named myfirstprogram.c with the following contents: #include <stdio.h> int main(int argc, char *argv[]) { } printf( Who am I?\n ); return 0; 2. Using the chmod command, change the permission of your file myfirstprogram.c so that no one other than you can read this file. 3. Give the full path of your file (using pwd ) to your neighbour. Ask your neighbour to try to read the content of your file using the less command on his/her terminal (and she/he should be unable to do so). 4. Compile the program into machine language by typing the following command: gcc myfirstprogram.c o myfirstprogram 5. Run your program by typing:./myfirstprogram

6. Experiment with the following linux commands which are very useful: a. uniq to print unique lines in a file b. ps to list the currently running processes in the system c. kill to terminate a currently running program d. umask to set the default file permissions e. nice to change the priority of your program f. sed to change the contents of files according to a pattern (more advanced than tr) g. xargs execute one command multiple times with multiple inputs taken from a file.