Information Networking Security and Assurance Lab National Chung Cheng University 1 What Linux is? Free Unix Like Open Source Network operating system.

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

Chapter One The Essence of UNIX.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
Linux+ Guide to Linux Certification, Second Edition
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
CSCI6303 – Principles of I.T. Fall  Student will become familiar with scripting in shell using Linux/Ubuntu  Student will write a script and execute.
Linux Shell. 2 Linux Command-Line Interface ■ Linux shells: A shell is a command interpreter that allows you to type commands from the keyboard to interact.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
LINUX Shell Scripting Advanced Issues
Overview of Linux CS3530 Spring 2014 Dr. José M. Garrido Department of Computer Science.
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”
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface (or Terminal) What is the filesystem tree.
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
Introduction to Shell Script Programming
Writing Shell Scripts ─ part 1 CSE 2031 Fall September 2015.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Lesson 1. PC vs. Multi-user System  Personal Computer – each user gets his/her own processor (or multicore processor).  Multi-user system – The processor,
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell The agency that.
Guide To UNIX Using Linux Fourth Edition
Unix Basics Chapter 4.
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.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
OPERATING SYSTEMS DESIGN UNIX BASICS & SHELL SCRIPTING.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Linux+ Guide to Linux Certification, Third Edition
Linux Operations and Administration
CS465 - UNIX The Bourne Shell.
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
LINUX programming 1. INDEX UNIT-III PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Problem solving approaches in Unix,Using.
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
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.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
Introduction to Programming Using C An Introduction to Operating Systems.
1 © 2000 John Urrutia. All rights reserved. Session 5 The Bourne Shell.
Chapter Six Introduction to Shell Script Programming.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Linux Commands C151 Multi-User Operating Systems.
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
Linux+ Guide to Linux Certification, Second Edition
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
Agenda The Bourne Shell – Part I Redirection ( >, >>,
 Prepared by: Eng. Maryam Adel Abdel-Hady
Learning Unix/Linux Based on slides from: Eric Bishop.
Linux Administration Working with the BASH Shell.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Lab 7 Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
Shell scripts – part 1 Cs 302. Shell scripts  What is Shell Script? “Shell Script is series of command written in plain text file. “  Why to Write Shell.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Introduction to Shells
Prepared by: Eng. Maryam Adel Abdel-Hady
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
System Programming and administration CS 308
The Linux Operating System
Shell Script Assignment 1.
Introduction Paul Flynn
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Lab 7 Shell Script Reference:
Presentation transcript:

Information Networking Security and Assurance Lab National Chung Cheng University 1 What Linux is? Free Unix Like Open Source Network operating system

Information Networking Security and Assurance Lab National Chung Cheng University 2 Who developed the Linux? In 1991, Linus Torvalds studied Unix at the University, where he used special educational experimental purpose operating system called Minix (small version of Unix and used in Academic environment). But Minix had it's own limitations. Linus felt he could do better than the Minix. So he developed his own version of Minix, which is now know as Linux. Linux is Open Source From the start of the day. For more information on Linus Torvalds, please visit

Information Networking Security and Assurance Lab National Chung Cheng University 3 How to get Linux?

Information Networking Security and Assurance Lab National Chung Cheng University 4 What's Kernel The hart of Linux OS. Manage resource of Linux OS.  Kernel decides who will use this resource, for how long and when. Perform the following tasks  I/O management  Process management  Device management  File management  Memory management Kernel Shell Applications

Information Networking Security and Assurance Lab National Chung Cheng University 5 Shell A command language interpreter that executes commands read from the standard input device (keyboard) or from a file.

Information Networking Security and Assurance Lab National Chung Cheng University 6 Most Popular Shells $ echo $SHELL

Information Networking Security and Assurance Lab National Chung Cheng University 7 Input – Output Redirection (I) > Redirector Symbol  Syntax: Linux-command > filename  To output Linux-commands result to file.  If file already exist, it will be overwritten else new file is created. EX: $ ls > myfiles

Information Networking Security and Assurance Lab National Chung Cheng University 8 Input – Output Redirection (II) >> Redirector Symbol  Syntax: Linux-command >> filename  To output Linux-commands result to END of file.  If file exist, it will be opened and new information will be written to END of file (appendix), without losing previous information, And if file is not exist, then new file is created. EX: $ date >> myfiles

Information Networking Security and Assurance Lab National Chung Cheng University 9 Input – Output Redirection (III) < Redirector Symbol  Syntax: Linux-command < filename  To take input to Linux-command from file instead of key-board. EX: $ cat < myfiles

Information Networking Security and Assurance Lab National Chung Cheng University 10 Pipe A pipe is a way to connect the output of one program to the input of another program without any temporary file. Pipes are used to run more than two commands ( Multiple commands) from same command line.  Syntax: command1 | command2

Information Networking Security and Assurance Lab National Chung Cheng University 11 Pipe Examples

Information Networking Security and Assurance Lab National Chung Cheng University 12 Variables in Linux Variable (a.k.a memory variable): Programmer can give a unique name to this memory location/address. In Linux, there are two types of variable  System variables - Created and maintained by Linux itself. This type of variable defined in CAPITAL LETTERS.  User defined variables (UDV) - Created and maintained by user. This type of variable defined in lower LETTERS.

Information Networking Security and Assurance Lab National Chung Cheng University 13 Some System variables You can change system variables by giving command like $ set, You can print any of the variables via “echo”  Ex: $ echo $USERNAME; $ echo $HOME

Information Networking Security and Assurance Lab National Chung Cheng University 14 How to define and print User defined variables (UDV) Syntax: variablename=value Ex:  $ no=10 # this is ok  $ 10=no # Error, NOT Ok, Value must be on right side of = sign. Q.1.How to Define variable x with value 10 and print it on screen  $ x=10  $ echo $x Q.2.How to Define variable xn with value Rani and print it on screen  $ xn=Rani  $ echo $xn

Information Networking Security and Assurance Lab National Chung Cheng University 15 Rules for Naming variable name (Both UDV and System Variable) Variable name must begin with Alphanumeric character or underscore character (_), followed by one or more Alphanumeric character. EX:  HOME  SYSTEM_VERSION  no Don't put spaces on either side of the equal sign when assigning value to variable. $ no=10(  ) $ no =10(X) Variables are case-sensitive, just like filename in Linux.  $ no=10  $ NO=11

Information Networking Security and Assurance Lab National Chung Cheng University 16 Some Good Questions (I) Q.1: How to print sum of two numbers, let's say 6 and 3  $ echo  This will print 6 + 3, not the sum 9  Try $ expr  How about $ expr 6+3 (please note that no space between 6 and 3)?

Information Networking Security and Assurance Lab National Chung Cheng University 17 Some Good Questions (II) Q.2:How to define two variable x=20, y=5 and then to print division of x and y (i.e. x/y)  $x=20  $ y=5  $ expr x / y Or  $ x=20  $ y=5  $ z=`expr x / y`  $ echo $z

Information Networking Security and Assurance Lab National Chung Cheng University 18 What is Shell Scripts? Shells are interactive.  It means shell accept command from you (via keyboard) and execute them. If you want to execute the sequence of commands, the you can store this sequence of command to text file and tell the shell to execute this text file instead of entering the commands. This is know as shell script.

Information Networking Security and Assurance Lab National Chung Cheng University 19 Why to Write Shell Script ? Shell script can take input from user, file and output them on screen. Useful to create our own commands. Save lots of time. To automate some task of day today life. System Administration part can be also automated.

Information Networking Security and Assurance Lab National Chung Cheng University 20 How to write shell script Write a script that will print "Knowledge is Power" on screen. $ cat > first # # My first shell script # clear echo "Knowledge is Power" $ cat > first # # My first shell script # clear echo "Knowledge is Power"

Information Networking Security and Assurance Lab National Chung Cheng University 21 How to Run Shell Scripts Shell Script does not get execution permission by default. Two Ways to run it 1.Use chmod command to give execution permission  Syntax: chmod +x shell-script-name OR Syntax: chmod 777 shell-script-name 2.Run our script as  Syntax:./your-shell-program-name  Ex: $./first OR /bin/sh &nbsh;&nbsh; your-shell-program-name  Ex:  $ bash first  $ /bin/sh first

Information Networking Security and Assurance Lab National Chung Cheng University 22 More on Running Shell Scripts Need to run the scripts in same directory where you created your script, if you are in different directory your script will not run. To Overcome this problem, there are two ways  specify complete path of your script when ever you want to run it from other directories like giving following command. Ex: $ /bin/sh /home/vivek/first  This take time and you have to remember complete path.

Information Networking Security and Assurance Lab National Chung Cheng University 23 Another Way To Run Shell Scripts Can be directly executed from prompt from any directory  All our executables files are installed in directory called /bin and /bin directory is set in your PATH setting.  Principles: It will look for current directory, if found shell will execute command from current directory, if not found, then Shell will Look PATH setting, and try to find our requested commands executable file in all of the directories mentioned in PATH settings, Procedures:  Create bin directory in your home directory and then copy your tested version of shell script to this bin directory. After this you can run you script as executable file without using $./shell $ cd $ mkdir bin $ cp first ~/bin $ first

Information Networking Security and Assurance Lab National Chung Cheng University 24 Use -v and -x option with sh or bash command to debug the shell script. Syntax: sh option { shell-script-name } OR bash option { shell-script-name } -v: Print shell input lines as they are read. -x: After expanding each simple- command, bash displays the expanded value of PS4 system variable, followed by the command and its expanded arguments. How to de-bug the shell script? $ cat > dsh1.sh # # Script to show debug of shell # tot=`expr $1 + $2` echo $tot $ chmod 755 dsh1.sh $./dsh1.sh $ sh -x dsh1.sh 4 5 # # Script to show debug of shell # tot=`expr $1 + $2` expr $1 + $2 ++ expr tot=9 echo $tot + echo 9 9

Information Networking Security and Assurance Lab National Chung Cheng University 25 One Small Test Q.6.Point out error if any in following script $ vi variscript # # # Script to test MY knowledge about variables! # myname=Vivek myos = TroubleOS myno=5 echo "My name is $myname" echo "My os is $myos" echo "My number is myno, can you see this number"

Information Networking Security and Assurance Lab National Chung Cheng University 26 The read Statement Use to get input (data from user) from keyboard and store (data) to variable. Syntax: read variable1, variable2,...variableN Following script first ask user, name and then waits to enter name from the user via keyboard. # #Script to read your name from key-board # echo "Your first name please:" read fname echo "Hello $fname, Lets be friend!" $ chmod 755 sayH $./sayH Your first name please: vivek Hello vivek, Lets be friend!

Information Networking Security and Assurance Lab National Chung Cheng University 27 Wild cards

Information Networking Security and Assurance Lab National Chung Cheng University 28 Shorthand at the Command Prompt (I) / - root directory./ - current directory./command_name - run a command in the current directory when the current directory is not on the path../ - parent directory ~ - home directory $ - typical prompt when logged in as ordinary user # - typical prompt when logged in as root or superuser ! - repeat specified command !! - repeat previous command

Information Networking Security and Assurance Lab National Chung Cheng University 29 Shorthand at the Command Prompt (II) & - run a program in background mode [Tab][Tab] - prints a list of all available commands. This is just an example of autocomplete with no restriction on the first letter. x[Tab][Tab] - prints a list of all available completions for a command, where the beginning is ``x'' [Ctrl]c - kill the current process [Ctrl]d - logout from the current terminal [Ctrl]z - send current process to the background reset - restore a terminal to its default settings

Information Networking Security and Assurance Lab National Chung Cheng University 30 Important Bash Shell Variables HOME - home directory, abbreviated as ~ PATH - directory paths to search for executable files. PS1 - prompt string. Things that can be put in the prompt string include \h (hostname), \u (username), \w (absolute pathname of working directory), \W (name of working directory w/o path), \d (date), \t (time).

Information Networking Security and Assurance Lab National Chung Cheng University 31 Linux Command Related with Process Linux is multi-user, multitasking OS. It means you can run more than two process simultaneously if you wish.