SANJAY GHODAWAT POLYTECHNIC

Similar documents
Linux Essentials Objectives Topics:

5/20/2007. Touring Essential Programs

Useful Unix Commands Cheat Sheet

CSCM98 Lab Class #5 Getting familiar with the command line

TestOut Linux Pro - English 4.0.x OBJECTIVE MAPPING: CompTIA Linux+ LX0-103

Chapter 9. Shell and Kernel

Part 1: Basic Commands/U3li3es

LPIC-1 System Administrator

UNIX System Programming Lecture 3: BASH Programming

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

Advanced Unix Programming Module 03 Raju Alluri spurthi.com

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

Linux Command Line Primer. By: Scott Marshall

UNIX Quick Reference

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

Computer Systems and Architecture

Shell Programming Systems Skills in C and Unix

UNIT V. Dr.T.Logeswari. Unix Shell Programming - Forouzan

Computer Systems and Architecture

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

Shell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved

Lab 2A> ADDING USERS in Linux

Perl and R Scripting for Biologists

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.

Hands-on Keyboard: Cyber Experiments for Strategists and Policy Makers

More Raspian. An editor Configuration files Shell scripts Shell variables System admin

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

Users, Groups and Permission in Linux

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

DAVE LIDDAMENT INTRODUCTION TO BASH

bash startup files Linux/Unix files stty Todd Kelley CST8207 Todd Kelley 1

Exam Linux-Praxis - 1 ( From )

Basic Linux (Bash) Commands

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

Introduction to the shell Part II

User & Group Administration

hash Remember the full pathname of a name argument head Output the first part of file(s) history Command History hostname Print or set system name

Last Time. on the website

CSE Linux VM. For Microsoft Windows. Based on opensuse Leap 42.2

Lecture 02: Linux Command Line

Files (review) and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

EECS2301. Example. Testing 3/22/2017. Linux/Unix Part 3. for SCRIPT in /path/to/scripts/dir/* do if [ -f $SCRIPT -a -x $SCRIPT ] then $SCRIPT fi done

Linux Essentials. Smith, Roderick W. Table of Contents ISBN-13: Introduction xvii. Chapter 1 Selecting an Operating System 1

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

System Administration

Unix Introduction to UNIX

RedHat. Rh202. Redhat Certified Technician on Redhat Enterprise Linux 4 (Labs)

RH-202. RedHat. Redhat Certified Technician on Redhat Enterprise Linux 4 (Labs)

List of Linux Commands in an IPm

Presented by Bill Genske Gary Jackson

Lab 2: Linux/Unix shell

Introduction to Linux Workshop 1

A shell can be used in one of two ways:

Assume that username is cse. The user s home directory will be /home/cse. You may remember what the relative pathname for users home directory is: ~

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

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

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

Introduction to Linux

Contents. xxvii. Preface

Some useful UNIX Commands written down by Razor for newbies to get a start in UNIX

Operating Systems Lab 1 (Users, Groups, and Security)

Welcome to getting started with Ubuntu Server. This System Administrator Manual. guide to be simple to follow, with step by step instructions

client X11 Linux workstation

ScazLab. Linux Scripting. Core Skills That Every Roboticist Must Have. Alex Litoiu Thursday, November 14, 13

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

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

22-Sep CSCI 2132 Software Development Lecture 8: Shells, Processes, and Job Control. Faculty of Computer Science, Dalhousie University

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

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science

User accounts and authorization

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

Shells & Shell Programming (Part B)

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

INd_rasN SOME SHELL SCRIPTING PROGRAMS. 1. Write a shell script to check whether the name passed as first argument is the name of a file or directory.

Assignment clarifications

Shell programming. Introduction to Operating Systems

Essentials for Scientific Computing: Bash Shell Scripting Day 3

Chapter-3. Introduction to Unix: Fundamental Commands

LOG ON TO LINUX AND LOG OFF

CST8207: GNU/Linux Operating Systems I Lab Seven Linux User and Group Management. Linux User and Group Management

Exercise 1: Basic Tools

Embedded Linux Systems. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Unix Tools / Command Line

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

UNIX. Basic UNIX Command

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

for more :-

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

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

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

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

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

Introduction to Linux

CS/CIS 249 SP18 - Intro to Information Security

NETW 110 Lab 5 Creating and Assigning Users and Groups Page 1

Defensie Exercises preparing for the exam.

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.

Roll No. :... Invigilator's Signature : UNIX AND SHELL PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Bash command line for Linux. adduser Add a user to the system. addgroup Add a group to the system. Create an alias

COMP 4/6262: Programming UNIX

Transcription:

EXPERIMENT NO. 01 Name of Experiment Implement following commands with their options: ps and kill. df and du mount and umount. (4 Hours) Prerequisite of. / execution of Basic knowledge about linux command. Linux Operating System. Open shell terminal Set ps command and get information of process. Set $ ps ag command for real time process monitoring. Use kill command to kill process by ID $kill 1020 Use killall command to kill all processes. Kill with process name $killall processname Stop all process $kill 0 Df command is used to check disk available space. $df $df h The du command shows the disk usage for a specific directory (by default, the current directory). $du c $du h Mount Command mount -t vfat /dev/sdb1 /media/disk Unmount Command $umount Check command result and notice that results. Do not kill system processes. Note down all results after command execution. Describe Linux file structure in details.

EXPERIMENT NO. 02 Name of Experiment Implement grep and tar commands. (4 Hours) Prerequisite of. / execution of Open Linux shell Before performing grep command need files for searching data Type in shell Create sample files in linux in home directory $cat file1 One two three four $man grep Check grep manual and performing operating $grep two file Use different attributes Use tar command for archiving file $man tar $tar cvf test.tar /test1/test2 Use different parameters and attributes in grep and tar command examples. Note down result of different attributes used in examples Explain grep and tar commands with 4 examples.

EXPERIMENT NO. 03 Name of Experiment Prerequisite of. / execution of Implement setting of global and local environment variable, shell environment variables. (4 Hours) Open Linux shell $ echo $SHELL would give you the name of the current shell you are using. To see a list of the environment variables that are already set on your machine, type the following- $ env Display current environment variables- $set Printing shell, environment variables $printenv $env VAR1="blahblah" command_to_run command_options Creating Environment variables $test_var=testing $echo test_var $export test_var $echo $test_var e.g $export PATH=${PATH}:/home/cse/bin Removing Environment Variables $unset test_var Seting PATH variable $ PATH=$PATH:/home/rich/test Setting Shell variables $test_var='cse' To define a temporary value to a shell variable use the command: $set variable_name=value Use different parameters and attributes in shell commands Note down result of different attributes used in examples

EXPERIMENT NO. 04 Name of Experiment Create users, groups.set permissions and ownership. View the /etc/passwd file and describe its syntax. View the /etc/shadow file and describe its syntax. View the /etc/group file and describe its syntax. (4 Hours) Prerequisite of. Equipment/ Instrumentation Adding a new user Open Linux shell # /usr/sbin/useradd D You can test this by creating a new user account using the default system parameters # /usr/sbin/useradd test Changing the default values is a snap: # useradd -D -s /bin/tsch Removing a user # /usr/sbin/userdel -r test Modifying a user Usermod passwd and chpasswd # passwd test The chpasswd command reads a list of login name and password pairs (separated by a colon) from the standard input, and automatically encrypts the password and sets it for the user account. chsh, chfn, and chage # chfn test # finger rich # chfn test # finger test The /etc/group file Creating new groups # /usr/sbin/groupadd shared # /usr/sbin/usermod -G shared test Modifying groups # /usr/sbin/groupmod -n sharing shared Default file permissions $ touch newfile $ ls -al newfile $ umask Changing permissions Format: chmod options mode file

$ chmod 760 newfile $ ls -l newfile $ chmod o+r newfile Changing ownership The format of the chown command is: chown options owner[.group] file # chown dan newfile # ls -l newfile The /etc/passwd file $man passwd $ cat /etc/passwd The /etc/shadow file The /etc/shadow file contains one record for each user account on the system. A record looks like this: rich:$1$.ffck0ns$f1ugiyhq25wrb/hykcn020:11627:0:99999:7::: In between check Points Use ls command to check system result of operation. during / execution of Note down result of different attributes used in examples.

EXPERIMENT NO. 05 Name of Experiment Prerequisite of. / execution of Implement setting up and releasing of special permissions (SGID, SUID and sticky bit) and state their effects. (4 Hours) Open Linux shell The set user id (SUID): When a file is executed by a user, the program runs under the permissions of the file owner. The set group id (SGID): For a file, the program runs under the permissions of the file group. For a directory, new files created in the directory use the directory group as the default group. The sticky bit: The file remains (sticks) in memory after the process ends. to create a shared directory that always sets the directory group for all new files, all you need to do is set the SGID bit for the directory: $ mkdir testdir $ ls l $ chgrp shared testdir $ chmod g+s testdir $ ls l $ umask 002 $ cd testdir $ touch testfile $ ls -l Use different parameters and attributes in shell commands Note down result of different attributes used in examples

EXPERIMENT NO. 06 Name of Experiment Implement I/O Redirection and Pipes. (4 Hours) Prerequisite of. Output redirection The most basic type of redirection is sending output from a command to a file. The bash shell uses the greater-than symbol for this: command > outputfile $ date > test6 $ ls -l test6 $ cat test6 Now the contents of the test6 file contain the output from the who command. $ who > test6 $ cat test6 $ date >> test6 $ cat test6 The test6 file still contains the original data from the who command processed earlier, plus now it contains the new output from the date command. Input redirection The input redirection symbol is the less-than symbol (<): command < inputfile $ wc < test6 The wc command provides a count of text in the data. The inline input redirection symbol is the double less-than symbol (<<). Besides this symbol, you must specify a text marker that delineates the beginning and end of the data used for input. command << marker $ wc << EOF > test string 1 > test string 2 > test string 3 > EOF Pipes There are times when you need to send the output of one command to the input of another command. This process is called piping. The pipe symbol is the bar operator ( ): command1 command2 Now, using piping you can easily pipe the output of the rpm command directly to the sort

command to produce your results: $ rpm -qa sort / execution of Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)

EXPERIMENT NO. 07 Name of Experiment Write shell script to demonstrate use of conditional and loop control statements. Write a shell script that shows effects of quotes on the Output of a variable. Write a shell script that looks through all the files in the current directory for the string POSIX and then prints the name of these files to the standard output. (6 Hours) Prerequisite of. Here The syntax expressed the how to use loops: if [ expression ] then Statement(s) to be executed if expression is true fi If else if [ expression ] then Statement(s) to be executed if expression is true else Statement(s) to be executed if expression is not true fi While Loop while command do Statement(s) to be executed if command is true Done For Loop for var in word1 word2... wordn do Statement(s) to be executed for every word. done try this Code for standard output #finding name of files echo current working directory files

find. print find. -name POSIX ls > search.txt ls > find. name POSIX #find name \*.txt.posix.txt ls > search.txt / execution of Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)

EXPERIMENT NO. 08 Name of Experiment Write shell script to implement following test commands : For string comparisons. For numeric comparisons. For file comparisons (6 Hours) Prerequisite of. String Comparison Example 1: $ cat > test9b # testing string sort order val1=testing val2=testing if [ $val1 \> $val2 ] then echo "$val1 is greater than $val2" else echo "$val1 is less than $val2" fi $ sh test9b Testing is less than testing $ sort testfile Numeric Comparison Example 1: $ cat > test5 # using numeric test comparisons val1=10 val2=11 if [ $val1 -gt 5 ] then echo "The test value $val1 is greater than 5" fi if [ $val1 -eq $val2 ] then echo "The values are equal" else echo "The values are different" fi

echo The first test condition: if [ $val1 -gt 5 ] echo tests if the value of the variable val1 is greater than 5. The second test condition: if [ $val1 -eq $val2 ] echo There is a limitation to the test numeric conditions though. Try this script: #sh test5 File Comparison Example 1: $ cat > test11 # look before you leap if [ -d $HOME ] then echo "Your HOME directory exists" cd $HOME ls -a else echo "There s a problem with your HOME directory" fi $ sh test11 / execution of Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)

EXPERIMENT NO. 09 Name of Experiment Write shell script that : Uses command line parameters. Counts number of parameters. Implements shift command. Implements processing option with parameter values. (6 Hours) Prerequisite of. Command Line Parameter Example 1 $ cat > test4 # handling lots of parameters total=$[ ${10} * ${11} ] echo The tenth parameter is ${10} echo The eleventh parameter is ${11} echo The total is $total $ sh test4 1 2 3 4 5 6 7 8 9 10 11 12 Counting Parameters Example 1 $ cat > test8 # getting the number of parameters echo There were $# parameters supplied. $ sh test8 There were 0 parameters supplied. $ sh test8 1 2 3 4 5 There were 5 parameters supplied. $ sh test8 1 2 3 4 5 6 7 8 9 10 There were 10 parameters supplied. $ sh test8 "Rich Blum" There were 1 parameters supplied. $ Shift Command

/ execution of Example 2 $ cat > test14 # demonstrating a multi-position shift echo "The original parameters: $*" shift 2 echo "Here s the new first parameter: $1" $ sh test14 1 2 3 4 5 Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)

EXPERIMENT NO. 10 Name of Experiment Write shell script : To implement redirection of Input script. For redirecting file descriptors. Creating input file descriptor. (6 Hours) Prerequisite of. Redirecting Input in Scripts Example 1 $ cat test12 # redirecting file input exec 0< testfile count=1 while read line do echo "Line #$count: $line" count=$[ $count + 1 ] done $./test12 Redirecting file descriptors Example 1 $ cat test14 # storing STDOUT, then coming back to it exec 3>&1 exec 1>test14out echo "This should store in the output file" echo "along with this line." exec 1>&3 echo "Now things should be back to normal" $./test14 Now things should be back to normal $ cat test14out This should store in the output file along with this line. $

/ execution of Creating input file descriptors Example 1 $ cat test15 # redirecting input file descriptors exec 6<&0 exec 0< testfile count=1 while read line do echo "Line #$count: $line" count=$[ $count + 1 ] done exec 0<&6 read -p "Are you done now? " answer case $answer in Y y) echo "Goodbye";; N n) echo "Sorry, this is the end.";; esac $./test15 Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)

EXPERIMENT NO. 11 Name of Experiment Practice sed editor and gawk utility. (6 Hours) Prerequisite of. Sed The format for using the sed command is: sed options script file $ echo "This is a test" sed s/test/big test/ This is a big test $ Using multiple editor commands in the command line To execute more than one command from the sed command line, just use the -e option: $ sed -e s/brown/green/; s/dog/cat/ data1 Reading editor commands from a file $ cat script1 s/brown/green/ s/fox/elephant/ s/dog/cat/ $ sed -f script1 data1 Gawk The gawk command format The basic format of the gawk program is: gawk options program file Reading the program script from the command line $ gawk {print "Hello John!"} Using data field variables $ cat data3 One line of test text. Two lines of test text. Three lines of test text. $ gawk {print $1} data3 Using multiple commands in the program script $ echo "My name is Rich" gawk {$4="Dave"; print $0} My name is Dave $ Reading the program from a file $ cat script2

/ execution of { print $5 " s userid is " $1 } $ gawk -F: -f script2 /etc/passwd Running scripts before processing data $ gawk BEGIN {print "Hello World!"} Hello World! $ $ gawk BEGIN {print "Hello World!"} {print $0} Running scripts after processing data $ gawk BEGIN {print "Hello World!"} {print $0} END {print "byebye"} $ cat script4 BEGIN { print "The latest list of users and shells" print " Userid Shell" print "-------- -------" FS=":" } { print $1 " " $7 } END { print "This concludes the listing" } $ Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)

EXPERIMENT NO. 12 Name of Experiment Write a shell script using functions. Modify it to handle function with parameters, function returning values. Write shell script for handling array variables. Write shell script that uses function returning true or false result. (6 Hours) Prerequisite of. Returning a Value Example 1 $ cat test4 # testing the exit status of a function func1() { echo "trying to display a non-existent file" ls -l badfile } echo "testing the function:" func1 echo "The exit status is: $?" $./test4 Example 2 $ cat test5 # using the return command in a function function dbl { read -p "Enter a value: " value echo "doubling the value" return $[ $value * 2 ] } dbl echo "The new value is $?" $ Passing parameters to a function $ cat badtest1 # trying to access script parameters inside a function function badfunc1 { echo $[ $1 * $2 ] } if [ $# -eq 2 ] then

/ execution of value=`badfunc1` echo "The result is $value" else echo "Usage: badtest1 a b" fi $./badtest1 Usage: badtest1 a b $./badtest1 10 15./badtest1: * : syntax error: operand expected (error token is "* ") The result is $ Passing arrays to functions $ cat test10 # array variable to function test function testit { local newarray newarray=(`echo "$@"`) echo "The new array value is: ${newarray[*]}" } myarray=(1 2 3 4 5) echo "The original array is ${myarray[*]}" testit ${myarray[*]} $./test10 Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)

EXPERIMENT NO. 13 Name of Experiment Write a shell script which checks disk space and store the value to the variable and display it. Write a shell script that tests connectivity with the PCs whose IPs are provided as command line parameters. (6 Hours) Prerequisite of. / execution of Use different parameters and attributes in shell commands Note down result of different attributes used in examples Subject Teacher (Mr. Pise S. P ) HOD (Mr. Patil P.R.)