Your SlideShare is downloading. ×
0
Lesson 6-Using Utilities to Accomplish Complex Tasks
Overview  <ul><li>Creating and executing a script to list user information. </li></ul><ul><li>Listing directories and file...
Creating and Executing a Script to List User Information <ul><li>Creating a script. </li></ul><ul><li>Executing a script. ...
Creating a Script  <ul><li>A series of commands can be executed repeatedly/automatically by placing them in a script file....
Executing a Script  <ul><li>The commands in a file can be executed in two ways: </li></ul><ul><ul><li>Instructions can be ...
Executing a Script  <ul><li>The command used to make the shell executable is “chmod +x filename”. </li></ul><ul><li>By def...
Listing Directories and Files  Separately  <ul><li>Selecting only directories / files: </li></ul><ul><ul><li>The “ls –F | ...
Listing Directories and Files  Separately  Selecting Directories Using Multiple Utilities
Listing Directories and Files  Separately  Interpretation by grep Using –v option
Listing Directories and Files  Separately  <ul><li>Adding comments to scripts: </li></ul><ul><ul><li>The # (pound) sign is...
Identifying Changes Made to Files in a Directory  <ul><li>Collecting data about files in a directory: </li></ul><ul><ul><l...
Identifying Changes Made to Files in a Directory  <ul><li>Comparing file information: </li></ul><ul><ul><li>The “comm” com...
Identifying Changes Made to Files in a Directory  <ul><li>Comparing file information: </li></ul><ul><ul><li>The “diff” com...
Creating a Complex Script  <ul><li>Determining the number of unique words in a file. </li></ul><ul><li>Removing punctuatio...
Determining the Number of Unique Words in a File  <ul><li>The “uniq” utility is used to: </li></ul><ul><ul><li>Provide a l...
Determining the Number of Unique Words in a File  <ul><li>The uniq utility outputs both, unique lines as well as single co...
Determining the Number of Unique Words in a File  <ul><li>The following things must be ensured for the uniq utility to wor...
Removing Punctuation  Shell and Utility Interpretation
Converting Characters to Lowercase  Shell and tr Interpretation
Putting Each Word on a Line  <ul><li>To remove duplicate words using the uniq utility, the data must be modified to ensure...
Putting Each Word on a Line  <ul><li>The “man ascii” command is used to examine the ASCII characters and their associated ...
Putting Each Word on a Line  Using tr Utility to Replace Characters
Removing Blank Lines  A View from the Shell
Sorting the Lines  <ul><li>The “sort” command can be used to sort the output such that all lines containing the same word ...
Summary  <ul><li>A series of commands placed in a script file can be repeatedly executed, avoiding errors and saving time....
Upcoming SlideShare
Loading in...5
×

intro unix/linux 06

3,135

Published on

using utilities to accomplish complex tasks

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,135
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
232
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "intro unix/linux 06"

  1. 1. Lesson 6-Using Utilities to Accomplish Complex Tasks
  2. 2. Overview <ul><li>Creating and executing a script to list user information. </li></ul><ul><li>Listing directories and files separately. </li></ul><ul><li>Identifying changes made to files in a directory. </li></ul><ul><li>Creating a complex script. </li></ul>
  3. 3. Creating and Executing a Script to List User Information <ul><li>Creating a script. </li></ul><ul><li>Executing a script. </li></ul>
  4. 4. Creating a Script <ul><li>A series of commands can be executed repeatedly/automatically by placing them in a script file. </li></ul><ul><li>Placing commands in scripts helps avoid errors and save time. </li></ul><ul><li>The vi editor can be used to create a file. </li></ul><ul><li>The &quot;:wq&quot; commands are used to write to a file and return to the shell. </li></ul>
  5. 5. Executing a Script <ul><li>The commands in a file can be executed in two ways: </li></ul><ul><ul><li>Instructions can be given to the current shell to read the file (source) and execute all the commands. </li></ul></ul><ul><ul><li>The script file can be made executable, and a child shell can be started to read the script file and execute the commands. </li></ul></ul>
  6. 6. Executing a Script <ul><li>The command used to make the shell executable is “chmod +x filename”. </li></ul><ul><li>By default, the output of the script is redirected to the screen. </li></ul><ul><li>The output of the script can be redirected to a file. </li></ul>
  7. 7. Listing Directories and Files Separately <ul><li>Selecting only directories / files: </li></ul><ul><ul><li>The “ls –F | grep /” command is used to select only lines that contain directory names. </li></ul></ul><ul><ul><li>The “ls –F | grep / | column” command can be used to put the output into columns. </li></ul></ul><ul><ul><li>The “ls –F | grep –v / | column” command is used to select only files. </li></ul></ul>
  8. 8. Listing Directories and Files Separately Selecting Directories Using Multiple Utilities
  9. 9. Listing Directories and Files Separately Interpretation by grep Using –v option
  10. 10. Listing Directories and Files Separately <ul><li>Adding comments to scripts: </li></ul><ul><ul><li>The # (pound) sign is used to add comments to scripts. </li></ul></ul><ul><ul><li>Ensure that the # sign is placed at the beginning of each line. </li></ul></ul><ul><ul><li>The pound (#) sign cannot be used inside a long command line. </li></ul></ul>
  11. 11. Identifying Changes Made to Files in a Directory <ul><li>Collecting data about files in a directory: </li></ul><ul><ul><li>The “ls –l directory name” command can be used to provide information about the files in a particular directory. </li></ul></ul><ul><ul><li>The output of the code can also be redirected to another file by the command &quot;ls -l directoryname > filename”. </li></ul></ul><ul><ul><li>The information includes the current status of each file, such as permissions, date of modification, owner, etc. </li></ul></ul>
  12. 12. Identifying Changes Made to Files in a Directory <ul><li>Comparing file information: </li></ul><ul><ul><li>The “comm” command is used to identify the common aspects between two files. </li></ul></ul><ul><ul><li>It requires two arguments – the names of the two the files that are to be compared. </li></ul></ul><ul><ul><li>The command gives three columns of output – lines unique in the first file, lines unique in the second file, and lines in common. </li></ul></ul>
  13. 13. Identifying Changes Made to Files in a Directory <ul><li>Comparing file information: </li></ul><ul><ul><li>The “diff” command is used to identify the differences between two files. </li></ul></ul><ul><ul><li>It requires two arguments – the names of the two files to be compared. </li></ul></ul><ul><ul><li>The command gives three columns of output – lines unique in the first file, lines unique in the second file, and lines common to the two files. </li></ul></ul>
  14. 14. Creating a Complex Script <ul><li>Determining the number of unique words in a file. </li></ul><ul><li>Removing punctuation. </li></ul><ul><li>Converting characters to lowercase. </li></ul><ul><li>Putting each word on a line. </li></ul><ul><li>Removing blank lines. </li></ul><ul><li>Sorting the lines. </li></ul>
  15. 15. Determining the Number of Unique Words in a File <ul><li>The “uniq” utility is used to: </li></ul><ul><ul><li>Provide a list of unique words in a file. </li></ul></ul><ul><ul><li>The number of times that each word is used. </li></ul></ul><ul><ul><li>The number of unique words. </li></ul></ul>
  16. 16. Determining the Number of Unique Words in a File <ul><li>The uniq utility outputs both, unique lines as well as single copies of any lines that are duplicate and adjacent. </li></ul><ul><li>The utility deletes identical lines. </li></ul><ul><li>The uniq utility deletes only those lines that are identical and adjacent. </li></ul>
  17. 17. Determining the Number of Unique Words in a File <ul><li>The following things must be ensured for the uniq utility to work properly: </li></ul><ul><ul><li>Punctuation and blank lines must be removed. </li></ul></ul><ul><ul><li>Differences in case for the same word must be reconciled. </li></ul></ul><ul><ul><li>The words must be one word to a line in a sorted order. </li></ul></ul>
  18. 18. Removing Punctuation Shell and Utility Interpretation
  19. 19. Converting Characters to Lowercase Shell and tr Interpretation
  20. 20. Putting Each Word on a Line <ul><li>To remove duplicate words using the uniq utility, the data must be modified to ensure that each word is on a line by itself. </li></ul><ul><li>The new line character “ ” is used to separate lines in a file. </li></ul><ul><li>The ASCII character code 012 can also be used to separate lines in a file. </li></ul>
  21. 21. Putting Each Word on a Line <ul><li>The “man ascii” command is used to examine the ASCII characters and their associated codes. </li></ul><ul><li>TAB characters can also be replaced with new line characters. </li></ul>
  22. 22. Putting Each Word on a Line Using tr Utility to Replace Characters
  23. 23. Removing Blank Lines A View from the Shell
  24. 24. Sorting the Lines <ul><li>The “sort” command can be used to sort the output such that all lines containing the same word are on adjacent lines. </li></ul><ul><li>The “uniq –c” command can be used to remove all duplicate lines. </li></ul><ul><li>The “sort –rn” command can be used to list the most frequently used words first. </li></ul>
  25. 25. Summary <ul><li>A series of commands placed in a script file can be repeatedly executed, avoiding errors and saving time. </li></ul><ul><li>The ls utility provides a list of all the files and subdirectories in the current directory. </li></ul><ul><li>The # sign is used to add comments to script files. </li></ul><ul><li>The pipeline feature of UNIX is very useful and is central to manipulating data effectively with UNIX utilities. </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×