CMPT 471 Networking II Linux Primer 1© Janice Regan, 2013.

Slides:



Advertisements
Similar presentations
1 Introduction to UNIX Ke Liu
Advertisements

NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
©Colin Jamison 2004 Introduction to Linux Colin Jamison.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Preparation for working in the CSIL Basic LINUX operations.
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
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.
The Unix Shell. Operating System shell The shell is a command interpreter It forms the interface between a user and the operating system When you log.
Unix Basics. Systems Programming: Unix Basics 2 Unix Basics  Unix directories  Important Unix file commands  File and Directory Access Rights through.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Linux Commands LINUX COMMANDS.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Learning basic Unix command IT 325 operating system.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
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”
Introduction to Unix Bent Thomsen Institut for Datalogi Aalborg Universitet.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
LIN Unix Lecture 3 Hana Filip. LIN UNIX Resources UNIX Tutorials UNIX help for.
Linux+ Guide to Linux Certification, Second Edition
Introduction to Linux Azzam Mourad COEN 346.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
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.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
CMPT 471 Networking II Course Information 1© Janice Regan, 2013.
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.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
Welcome to CS323 Operating System lab 1 TA: Nouf Al-Harbi NoufNaief.net.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: whereis, which, whoami, finger, passwd, cal, date Working with Files: cat, more, less.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
Introduction to Programming Using C An Introduction to Operating Systems.
Getting Started UNIX InKwan Yu Topics Unix Commands Unix System calls C function calls.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
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.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
1 CS3695/M6-109 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Learning basic Unix command It 325 operating system.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
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.
Learning Unix/Linux Based on slides from: Eric Bishop.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Laboratory 1.2a1 First steps with Unix - Lab Boris Steipe Department of Biochemistry Department.
UNIX Basics Matt Hayward October 18, 2016 LS560 – Information Technology for information professionals.
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Tutorial of Unix Command & shell scriptS 5027
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Andy Wang Object Oriented Programming in C++ COP 3330
Some Linux Commands.
C151 Multi-User Operating Systems
Shell Script Assignment 1.
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
Using Linux Commands Lab 3.
Tutorial of Unix Command & shell scriptS 5027
Andy Wang Object Oriented Programming in C++ COP 3330
Linux Shell Script Programming
Linux Commands LINUX COMMANDS.
LPI Linux Certification
Presentation transcript:

CMPT 471 Networking II Linux Primer 1© Janice Regan, 2013

Shell Scripts  A shell script is an executable file containing a series of shell commands. When the shell script is executed the commands in the file are executed in sequence by the shell.  A shell script records a series of command line actions and easily executes them again and again  Assures repeatability of experiments and processes  Allows long series of commands to be easily tested and debugged  There are different shell scripting languages such as  csh (C shell), tcsh  sh (Bourne shell), bash (Bourne again shell)  Perl …… © Janice Regan,

Selecting a Shell Script Language  On the command line type  the name of the shell followed by return to enter the shell.  exit followed by return to leave the shell.  To determine which default shell you are presently using echo $SHELL finger youruserid (your default shell)  The present shell will be indicated by the prompt  To indicate which shell to use inside a shell script  in the first line of your script file#! /bin/csh  To indicate which shell to use when executing a shell script called scriptname  bash scriptname arguments or csh scriptname arguments © Janice Regan,

Executing a Shell Script  Your script file must be executable, you will need to change the permissions to make it executable (discuss how later in this lecture)  Executing a shell script called scriptname  bash scriptname arguments  csh scriptname arguments  source scriptname arguments ./scriptname arguments © Janice Regan,

Using Basic Unix Commands  Any basic Unix command can be run from the command line, or from within a shell script  To work with shell scripts you must first be familiar with basic Unix commands  Commands are used to move around within the file system, to create and operate on files, to interact with the operating system © Janice Regan,

Some basic commands  Remember UNIX is case sensitive  yppasswd username (username is optional)  Executed from your command line  Will ask you to input your old password and your new passwd twice  You can only change your own passwd unless you are root  man commandname or info commandname  Tell me how to use the command with name commandname  su  Become the root user (superuser, substitute user)  You will need to be root to complete many of your assignments. Do so with care..  whoami Tell me my username © Janice Regan,

Directories  Directory creation, navigation, removal  mkdir directorynamemake directory directoryname  rmdir directorynameremove empty directory  cd directorypathgo to directory directorypath  ls directorypathlist files in directory directorypath  cdreturn to your home directory  lslist files in this directory  pwdshow path to and name of current directory  cd..Move to the parent directory of this directory (one layer further up the directory tree © Janice Regan,

Directory structure Dir1 Dir5Dir6Dir7 © Janice Regan,  In myhome  cd Dir2 (goes to Dir2 )  cd Dir2/Dir5 (goes to Dir5 )  In Dir5  cd.. (goes to Dir3)  cd../.. Or cd (goes to myhome)  cd../Dir6 (goes to Dir6)  Anywhere cd will take you to myhome (your home directory)  cd / takes you to the root directory myhome Dir2Dir3Dir4

Root file structure © Janice Regan,

Files  To make a file open it using your favorite text editor  mv filepath1 filepath2  Moves (renames) a file or directory  mv a b file previously named a is now named b  mv a../a file a is moved from the present directory to the parent directory of the present directory  rm filepathremoves (deletes) a file  rm a deletes file a from the current directory  rm../a removes file a from the parent of the present directory  grep pattern filepaths  Find all occurrences of pattern in requested files © Janice Regan,

Files  more filename or less filename  Displays contents of file filename one page (screen) at a time  cp filename1 filename2  Make a copy of filename1 with name filename2  cat filename1 filename2 filename3  Will print the contents of each file in sequence Contents of filename1 Contents of filename2 Contents of filename3 © Janice Regan,

Wildcards  Wildcards are used to represent multiple possibilities  * matches any number of characters  ? Matches a single character  Examples  ls a? List all files in the current directory beginning with a and having a name of length 2 characters.  grep mystring */*file Find all occurences of the string “mystring” in all files whose names end with the string “file”. The files ending with string “file” must be in a subdirectory of the present directory  rm [a-c]* Remove all files with filenames beginning with a b or c from the current directory © Janice Regan,

Redirection  Redirect input and/or output  > filename redirect standard output from screen to file. cat file1 file2 file3 > f4 A new file f4 is opened and the contents of file1, file2 and file 3 are successively added to the file f4. If f4 exists it will be overwritten.  < filename take input from file filename a.out < datafile (a.out is the default output file for a compiled executable)  >> filename redirect standard output from screen to file. Appends output to an existing file cat file1 file2 file3 >> f4 The contents of file1 then file2 then file3 will be successively appended to the current contents of f4 © Janice Regan,

Piping  Piping allows you to send the output of one process to become the input of another process without using io to store it in an intermediate file  ls a* | more List the files in the current directory whose names start with a, one page at a time © Janice Regan,

File Permissions  Can use ls –l to find present permission for files  drwxrwxrwxfor directory  -rwxrwxrwxfor file u g o  3 sets of permissions  User (u) group (g) other(o)  Each set allows or disallows read write & or execute  rwx (allow all)  rw- (read write allowed)  r - - (read only)  Order of sets is ugo © Janice Regan,

Setting File Permissions: 1  Permissions can be reset by using chmod  chmod can specify permission in two ways  Numeric values read(4) write(2) execute(1). Sum desired values to give one digit permission value for each set Read write and execute 7, Write 2, Read and Execute 5  Adding or removing particular permissions Add execution permissions for user chmod u+x filename Remove write permissions for other chmod o+w filename Add read permissions for everyone chmod a+r filename © Janice Regan,

File Permissions Examples  chmod u-x filename  (remove owners execute permission)  chmod a+w filename  (make the file readable for all users)  chmod 644 filename  (make the file readable for all users but writeable only by the owner)  chown newowner filename  (you must own the file or be root)  chgroup newgroup filename © Janice Regan,

Processes  Command &  Run command as a background process  cntrlZ  Suspend (temporarily stop) foreground process  bg Move suspended process to background  fg Move background process or suspended process to the foreground  cntrlC  Terminate the foreground process © Janice Regan,

Processes  ps or ps -l  List information about all current processes  kill pidnumber  Kill background process with PID pidnumber  (use ps to find the pidnumber of the process) ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 8 S ? 273 ? pts/38 0:01 csh 8 S ? 296 ? pts/38 0:00 bash  To assure a process will die use kill -9 pidnumber © Janice Regan,

Checking shared memory  check after your process terminates ipcs Shared Memory Segments key shmid owner perms bytes nattch status 0x jregan dest Semaphore Arrays key semid owner perms nsems 0x dwlouie Message Queues key msqid owner perms used-bytes messages © Janice Regan,

When shared memory is left  When you still have entries in the shared memory section  Look at the value in the nattach (number of attached processes) if it is 0 then you can remove the memory segments using the provided script cleanSem © Janice Regan,

Using the cleanSem script  Copy the script from the class website  Change the mode of the file you now have in your LINUX directory so it can be executed  Chmod +x cleanSem  Run the script twice. To run ./cleanSem © Janice Regan,

When shared memory is left  When you still have entries in the shared memory section  Look at the value in the nattach (number of attached processes) if it is not 0 then the memory segments are still connected to at least one process  You need to find and remove that process © Janice Regan,

Removing processes (300)  Find the processes that are connected to your shared memory  If your userid is myuserid ps ux | grep myuserid | grep fork  Look at the resulting list of processes, finding one that did not start at the time you logged in. Kill that process (kill -9 processid) © Janice Regan,

Removing other processes  Find the processes that are part of your last run.  If your userid is myuserid and you ran executable./myprog ps ux | grep myprog  Kill the processes that include./myprog © Janice Regan,