Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.

Slides:



Advertisements
Similar presentations
In the last Session… ls -l command seven fields nine permissions of a file ls -ld file ownership file permissions (three-tiered file protection system)
Advertisements

Shell Script Assignment 1.
LINUX System : Lecture 3 (English-Only Lecture) Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University Acknowledgement.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
It's a binary file kept under specific directory.
Linux+ Guide to Linux Certification, Second Edition
Lesson 22 – Introduction to Linux Systems Administration.
Guide To UNIX Using Linux Third Edition
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Guide To UNIX Using Linux Third Edition
Unix Filters Text processing utilities. Filters Filter commands – Unix commands that serve dual purposes: –standalone –used with other commands and pipes.
©NIIT Pipes and Filters Lesson 2B / Slide 1 of 28 Introduction to Linux Pre-Assessment Questions 1.Consider the following statements: Statement A: A text.
Advanced File Processing
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Exam Revision. Exam Details Time 90 minutes (1hour 30 minutes). Six questions! How long per question? Five parts per question. How long for each part?
Guide to Linux Installation and Administration, 2e1 Chapter 8 Basic Administration Tasks.
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.
Guide To UNIX Using Linux Fourth Edition
LIN 6932 Unix Lecture 6 Hana Filip. LIN 6932 HW6 - Part II solutions posted on my website see syllabus.
Unix Talk #2 (sed). 2 You have learned…  Regular expressions, grep, & egrep  grep & egrep are tools used to search for text in a file  AWK -- powerful.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Introduction to Unix (CA263) File Processing. Guide to UNIX Using Linux, Third Edition 2 Objectives Explain UNIX and Linux file processing Use basic file.
File Permissions. What are the three categories of users that apply to file permissions? Owner (or user) Group All others (public, world, others)
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Module 4 - File Security. Security Overview File Ownership Access to Files and Dircetories Changing File and Directory Ownership Changing File and Directory.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command to search for.
Linux+ Guide to Linux Certification, Third Edition
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
Chapter Five Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
Introduction to Unix – CS 21 Lecture 12. Lecture Overview A few more bash programming tricks The here document Trapping signals in bash cut and tr sed.
EMT 2390L Lecture 5 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
Lesson 4-Mastering the Visual Editor. Overview Introducing the visual editor. Working in an existing file with vi. Understanding the visual editor. Navigating.
40 Years and Still Rocking the Terminal!
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
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.
Tony Kombol.  man  on-line user manual  man command_you_want_info_on  type q to exit  examples:  for ls (list directory) ▪ man ls  for cp (copy)
File System Security ls -l. First Columm d = directory l = symbolic link b = block special file c = character special file p = fifo (or named pipe) special.
Linux+ Guide to Linux Certification, Second Edition
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Lesson 6-Using Utilities to Accomplish Complex Tasks.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
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.
Linux Administration Working with the BASH Shell.
Tutorial of Unix Command & shell scriptS 5027
Lesson 5-Exploring Utilities
Getting started with CentOS Linux
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Some Linux Commands.
CS314 – Section 5 Recitation 1
Shell Script Assignment 1.
PROGRAMMING THE BASH SHELL PART IV by İlker Korkmaz and Kaya Oğuz
Unix Operating System (Week Two)
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
Guide To UNIX Using Linux Third Edition
Tutorial of Unix Command & shell scriptS 5027
Unix Talk #2 (sed).
Getting started with CentOS Linux
LPI Linux Certification
Presentation transcript:

Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program as a background process More Unix/Linux utilities Search and Replace utilities (grep, sed, awk) Security utilities Using vi editor Writing a basic shell script 1

Lecture 02CS311 – Operating Systems 1 2 Redirection Redirection can be either output or input redirection Output redirection – “>” Sends output to the file listed after the > instead of to stdout (usually the monitor). – A new file is created in the instance above if a file does not exist. The file will be replaced if it exists. – “>>” same as above but appends the contents to a file if it exists Input redirection is achieved by “<“ 2

Pipes Very important feature in a Linux system Pipes enable us to execute more than one command in a single line. Pipes are represented by “|” symbol Syntax Prompt> command1 | command2 | command3 … Lecture 02CS311 – Operating Systems 1 3

Terminating a command Ctrl + C – Terminates a command/process Ctrl + Z – Suspends a command/process Ctrl + D – End of file (EOF) Lecture 02CS311 – Operating Systems 1 4

Running programs in background Running program as a background – Insert “&” at the end of command to run it in the background (bg command has similar effect) – fg command brings the process to the foreground “ps” list the processes currently running – -a option list all processes “kill” command terminates a process Lecture 02CS311 – Operating Systems 1 5

Browsing through history Browse through the command history using up and down cursor keys when in the prompt Search a previously executed command using Ctrl + r Lecture 02CS311 – Operating Systems 1 6

Lecture 02CS311 – Operating Systems 1 7 More UNIX Utilities wc - print the number of newlines, words, and bytes in files – wc –l prints only the number of lines in a file Global Regular Expression Print (grep) – Search text utility from the command prompt – Syntax: grep “pattern” filename – “pattern” can be simple keyword search or regular expressions tr - translate characters in a file – Syntax: tr “source_char” “target_char” < filename cut – to separate sections from files 7

Security Utilities - User User is any person who can access a linux system. Two types of users are added by default when linux is installed – Regular user – Root user/Administrator We can login as root using command “su –” (su stands for switch user) or use “sudo” to perform root actions. To login as another user use “su –username” useradd command - add users to a linux system All users in a linux system is listed under /etc/passwd Lecture 02CS311 – Operating Systems 1 8

Security Utilities - Groups Linux categorizes users into groups. Some of the commands related to group are – groups - print the groups a user is in – groupadd – add a new group – newgrp - log in to a new group – chgrp - change group ownership – usermod -G – add users to the group /etc/group file lists all the group created in the Linux system Lecture 02CS311 – Operating Systems 1 9

Lecture 02CS311 – Operating Systems 1 10 File Permissions Unix/Linux filesystem security is achieved via 2 mechanisms: – file ownership (use chown command to change ownership of the file) – file permissions (chmod command discussed in next slide) 10

Lecture 02CS311 – Operating Systems 1 11 File Permissions - chmod File permissions are set for users/owners, groups and the rest of the world (others) Represented as “user/group/other” Octal number representation – 4 for read, 2 for write, 1 for execute – 741 -> > rwx for owner, r for group, x for world chmod 754 myDir – owner can ls, add files, and search the directory for a file – group can ls and search the directory for a file – world can search the directory (but cannot ls to see what else is there) 11

File Permissions - chmod Text representation – “u” user (owner) – “g” group – “o” other – “+” add permission – “-” remove permission – “r” read, “w” write, “x” execute Example: chmod u+rwx,g+rw,o+r file – gives rwx permission for user, rw for group and r for others Lecture 02CS311 – Operating Systems 1 12

Meaning of rwx on files and directories ReadWriteExecute Files A user can open and read a file. A user can make changes to a file. A user can execute the file or search contents in the file Directories A user can move into the directory A user can change the contents of a directory A user can list directory contents or search files Lecture 02CS311 – Operating Systems 1 13

Search and replace utilities grep used only for searching patterns or keywords in files. To search and replace contents of file then sed and awk are powerful utilities. Problem with sed and awk – poor documentation Check out the Resource page in our class website to learn more about these two commands. Lecture 02CS311 – Operating Systems 1 14

Sed Acronym for “Stream Editor” Used to search and replace file contents and make modifications to a file programmatically. Usage of commands in sed – “s” for substitution. Format “s/find pattern/replace string/g” – Example: ‘sed “s/day/night/g” text’ replaces all patterns “day” with “night”. If “g” not provided in the command, only the first occurrence is replaced. – “p” for print. Example: ‘sed “s/day/night/g”p text’ prints the output to stdout. Look into the script for more details Lecture 02CS311 – Operating Systems 1 15

Awk Excellent filter and report generator tool Particularly useful to manipulate tables General form of awk awk ‘BEGIN{action} #action performed at start pattern{action} #pattern is optional END{action}’ < file #action after script ends We can also include C statements inside action Positional variables - $1, $2, $3, etc. refers to the nth field in a string Lecture 02CS311 – Operating Systems 1 16

Using vi editor vi is an in-built text editor in UNIX To start vi – “vi filename” Two modes of vi – Command mode (mode at startup) – Text mode To go to text mode we can use these commands – “i” – insert in front of cursor – “a” – append text after cursor – “r” – replace one character Lecture 02CS311 – Operating Systems 1 17

Using vi editor In command mode you can use these commands – Cursor keys or “h,j,k,l” to move cursor – ^ - move cursor to start of line – $ - move cursor to end of line – dd – delete a line – :w – save file – :q – quit editor if file is saved – :q! – quit without changing file – :wq – save and quit editor We can go to command mode from text mode by pressing “Esc” Lecture 02CS311 – Operating Systems 1 18