agenda user profile file (.profile) –keyword shell variables linux (unix) filters –purpose...
TRANSCRIPT
![Page 1: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/1.jpg)
Agenda
• User Profile File (.profile)– Keyword Shell Variables
• Linux (Unix) filters– Purpose– Commands:
• grep, sort, awk
• cut, tr, wc, spell
![Page 2: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/2.jpg)
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)
![Page 3: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/3.jpg)
Useful Keyword Shell Variables
• HOME• PATH• MAIL• PS1 PS2• TERM• VISUAL• USER• PWD
![Page 4: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/4.jpg)
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
![Page 5: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/5.jpg)
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)
![Page 6: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/6.jpg)
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
![Page 7: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/7.jpg)
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
![Page 8: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/8.jpg)
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 <ENTER>– where . Represents the current (home directory)
followed by a space then .profile
![Page 9: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/9.jpg)
.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.
![Page 10: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/10.jpg)
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
![Page 11: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/11.jpg)
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 <ENTER>
For example: you can prevent overwriting a file by setting noclobber variable (set noclobber)
Refer to pages 336/337 for options
![Page 12: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/12.jpg)
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.
![Page 13: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/13.jpg)
Filters (Visual Example)
Filter
Filter Examples: Sort alphabetically, Select a string, etc...
StandardInput
StandardOutput
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
![Page 14: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/14.jpg)
Basic Filters
Basic Linux (Unix) Filters– sort– grep– awk– cut– tr– wc– spell
![Page 15: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/15.jpg)
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
![Page 16: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/16.jpg)
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
![Page 17: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/17.jpg)
Example Involving grep
• Assume you want to see if a file called file.name contains the text msaul– Type: grep msaul file.name <ENTER>
• Examples:• grep saul * (searches for saul pattern in all files in
current directory)
• finger | grep saul
• cat who.list | grep saul
![Page 18: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/18.jpg)
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]
![Page 19: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/19.jpg)
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
![Page 20: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/20.jpg)
cut
Writes out selected bytes, characters, or fields from each line of a file. cut [options] [list] [character] [file]
Options:
-c
-f
![Page 21: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/21.jpg)
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.
![Page 22: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/22.jpg)
Examples using cut
• For Example, to display several fields of each line of a file, enter:– cut -f 1,5 -d : /etc/passwd
![Page 23: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/23.jpg)
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
![Page 24: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/24.jpg)
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
![Page 25: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/25.jpg)
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
![Page 26: Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell](https://reader030.vdocuments.us/reader030/viewer/2022032313/56649e725503460f94b715f8/html5/thumbnails/26.jpg)
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