Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.

Slides:



Advertisements
Similar presentations
Shell Script Assignment 1.
Advertisements

CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Linux+ Guide to Linux Certification, Second Edition
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
Linux+ Guide to Linux Certification, Second Edition
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
Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Unix Filters Text processing utilities. Filters Filter commands – Unix commands that serve dual purposes: –standalone –used with other commands and pipes.
Shell Script Examples.
Advanced File Processing
Advanced Shell Programming. 2 Objectives Use techniques to ensure a script is employing the correct shell Set the default shell Configure Bash login and.
Notes Assignment #1 is due next Friday by 11:59 pm via Test #1 will be held Thursday February 18 at the start of class (one period long) Format:
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
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.
BIF703 stdin, stdout, stderr Redirection. stdin, stdout, stderr Recall the Unix philosophy “do one thing well”. Unix has over one thousand commands (utilities)
– 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.
Unix Shells Based on Glass & Abels’ Book CS240 Computer Science II.
Title Slide CSS 404/504 The UNIX Operating System (2) By Ralph B. Bisland, Jr.
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.
Shells. A program that is an interface between a user at a terminal and the computers resouces ▫The terminal may be real or an emulator The shell is.
Agenda Chapter 1: Linux (Unix) Features Commands (Chapters 2 & 3) Command Structure / Command line editing man, passwd, cal, date, whereis, which Working.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.
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
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
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.
Agenda Getting Started: Using Unix Unix Structure / Features Elements of the Unix Philosophy Unix Command Structure Command Line Editing Online Unix Command.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: whereis, which, whoami, finger, passwd, cal, date Working with Files: cat, more, less.
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
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.
Environment After log in into the system, a copy of the shell is given to the user Shell maintains an environment which is distinct from one user to another.
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
Agenda The Bourne Shell – Part II Special Characters Ambiguous File Reference Variable Names and Values User Created Variables Read-only Variables (Positional.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Second Edition
BIF713 Introduction to Linux. Agenda Getting Started: Using Linux Unix and Linux - Structure / Features Elements of the Linux Philosophy Linux Command.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
Learning Unix/Linux Based on slides from: Eric Bishop.
Agenda Customizing a Unix/Linux account Environment Introduction to Start-up Files (.bash_profile,.bashrc,.profile,.kshrc) Safe Methods for Changing Start-up.
Tutorial of Unix Command & shell scriptS 5027
Lesson 5-Exploring Utilities
System Programming and administration CS 308
Some Linux Commands.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands:
Shell Script Assignment 1.
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
John Carelli, Instructor Kutztown University
Guide To UNIX Using Linux Third Edition
Tutorial of Unix Command & shell scriptS 5027
Chapter Four UNIX File Processing.
Linux Shell Script Programming
Chapter 3 The UNIX Shells
Presentation transcript:

Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell

User Environment File.profile There are many files to set the account environment of the user. One of these files is called the.profile file. This file is used for both Bourne and Korn Shells. This file is used to: Set Variables(Keyword Shell Variables) Define Functions Run programs, or UNIX commands (similar to MS-DOS autoexec file)

Useful Keyword Shell Variables HOME PATH MAIL PS1 PS2 TERM VISUAL USER PWD

Keyword Shell Variables HOME (stored in /etc/passwd file) –Sets directory as your home directory (eg cd) PATH –Instructs shell to look in specified directories that may contain commands or programs MAIL –Specifies the file that stores your mail

Keyword Shell Variables PS1 –Stores a variable to display in a shell prompt –Eg. Display the current pathname in PS1 to be displayed at your shell prompt * PS2 –Stores a second variable to display in a shell prompt. For example, this secondary prompt will display when pressing enter before completing a UNIX command * * (see pg. 331 for special character definitions)

Keyword Shell Variables TERM –Stores the type of terminal that user will be working on –Usually, this variable is stored in.profile VISUAL –Specifies the text editor for keyboard movement & editing operations –eg VISUAL=vi or VISUAL=emacs

Keyword Shell Variables USER –Displays the current user (owner of account) –Useful in scripts or setup files PWD –Displays the current directory (present working directory) –Useful in scripts or setup files

Restarting the.profile File After you have “modified” your profile to meet your needs, you will need to run the.profile file to update any changes you have made. You can logout and login to your system, but there is an easier method: –Make sure you are in your home directory. At the prompt type:..profile –where. Represents the current (home directory) followed by a space then.profile

.bash_profile If you have installed Linux onto your home computer, and cannot locate the.profile, try searching for a file called.bash_profile in your home directory This file acts the same as.profile for your bash shell.

Other User Environment Files.sh_history –Used to store previously issued UNIX commands..exrc (“ex” run command file) –A file used to set “ex” editor (old name for vi edtitor) environment upon startup.mailrc (mail run command file) –A run command file that sets up mail environment for the user upon startup

Checking the Setting of Shell Variables You can check the assignment of the current shell variables (assigned from startup files) from typing the UNIX command: set For example: you can prevent overwriting a file by setting noclobber variable (set noclobber) Refer to pages 336/337 for options

Filters A filter is a device that “traps” materials (for example coffee grounds or dirt) to achieve a task (making coffee, etc.). In UNIX, command pipes are used to “trap” or perform an operations on data received as standard input and sends this “trapped data” as standard output or redirected to another utility.

Filters (Visual Example) Filter Filter Examples: Sort alphabetically, Select a string, etc... Standard Input Standard Output Pipe to | Input such as a UNIX command or data read from a file Displayed on Screen, or redirected to a File or “piped-to” another utility

Basic Filters Basic Linux (Unix) Filters –sort –grep –awk –cut –tr –wc –spell

sort (Basic) Used to sort or merge files. Particularly useful as a filter to sort standard input. Format: sort [options] [field-specifier-list][file-list] Examples sort output.txt who | sort | more ls | sort > listing.txt

grep (Basic) Used to search for a pattern which is stored in a file or files. Format: grep [options] pattern [file-list] Options: -c displays # of lines that contains a match -i ignores case sensitivity -n displays line number of file that contains a match -l displays only name of file that contains a match

Example Involving grep Assume you want to see if a file called file.name contains the text msaul –Type: grep msaul file.name Examples: grep saul * (searches for saul pattern in all files in current directory) finger | grep saul cat who.list | grep saul

awk (Basic) Search for a pattern or execute a program used to search and process a pattern. An example of a program file is a script that specifies the parameters of the search. Format: awk [pattern] [file-list] awk -f program-file [file-list]

Example Involving awk The awk command is a very useful and complex tool to search for and perform processing on data. Entering awk /pattern/ without a program file will default to the print program to display output For example awk /msaul/ * in current directory will display line contents in all files contained in the current directory

cut Writes out selected bytes, characters, or fields from each line of a file. cut [options] [list] [character] [file] Options: -c -f

cut Common Options: -c List Specifies character positions. For example, if you specify -c 1-72, the cut command writes out the first 72 characters in each line of the file. -f List Specifies a list of fields assumed to be separated in the file by a delimiter character, which is by default the tab character.

Examples using cut For Example, to display several fields of each line of a file, enter: –cut -f 1,5 -d : /etc/passwd

tr Used to replace (translates) characters such as string1 with string 2. Format: tr [options] [string1] [string2] Options: -d This option causes tr to delete characters that match those specified in string1 Refer to website for examples of the tr command

wc Used to display the number of lines, words and characters in a file Format: wc [options] file-list options: -c # of characters -l # of lines -w # of words

spell Used to check a file for spelling mistakes. The output will list the words not found in the dictionary (Available in Phobos not Tux) Format: spell [options] file-list options: -v display all words not in dictionary -b British spellings

Additional Redirection Commands (tee) Used to copy the standard input to the standard output and one or more files. Think of the letter T to send output into two different paths (eg screen and to a file) tee [options] file-list options: -a append output to existing files -i ignore interruptions