1 / 26

Agenda

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

aallman
Download Presentation

Agenda

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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)

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

  4. 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

  5. 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)

  6. 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

  7. 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

  8. 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

  9. .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.

  10. 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

  11. 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

  12. 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.

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

  14. Basic Filters • Basic Linux (Unix) Filters • sort • grep • awk • cut • tr • wc • spell

  15. 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

  16. 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

  17. 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

  18. 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]

  19. 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

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

  21. 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.

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

  23. 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

  24. 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

  25. 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

  26. 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

More Related