chapter 3 utilities
play

Chapter 3 Utilities Dr. Marjan Trutschl marjan.trutschl@lsus.edu - PowerPoint PPT Presentation

Chapter 3 Utilities Dr. Marjan Trutschl marjan.trutschl@lsus.edu Louisiana State University, Shreveport, LA 71115 Chapter 3: The Utilities Special Character Syntax Revisited Basic Utilities Working with Files Pipelines |


  1. Chapter 3 Utilities Dr. Marjan Trutschl marjan.trutschl@lsus.edu Louisiana State University, Shreveport, LA 71115

  2. Chapter 3: The Utilities ¤ Special Character – Syntax Revisited ¤ Basic Utilities ¤ Working with Files ¤ Pipelines ‘|’ Communicating Between Processes ¤ File Compression Utilities ¤ Displaying User and System Information

  3. Special Characters ¤ Special Characters: ¤ & ; | * / ’ ” ` [ ] ( ) $ < > { } # / \ ! ~ ¤ All have special meanings, escape them with ‘\’ or quotes -Double quotes don’t escape -Single quotes escape everything -’\’ escapes only one thing -The ‘$’ character changes it into a variable, which had a default value of zero

  4. Basic Utilities ¤ There Are Numerous Utilities ¤ You can do pretty much anything that you can think of ¤ If you don’t see a utility, then install it with a package manager like ‘apt-get’ for Linux or for Mac, try Homebrew, Nix or MacPorts ¤ Check the man page when you download them to figure them all out NEdit is a graphical text editor with syntax highlighting for Linux. It wasn’t installed, so I downloaded it and installed it with a single command.

  5. Basic Utilities ¤ Try These Handy Utilities: ¤ ‘ls’: Lists the files in the current directory, try adding ‘-ah’ ¤ ‘rm’: Deletes a file, adding ‘-i’ ask first, ‘-r’ delete a directory ¤ ‘cat’: Displays a file

  6. Working with Files ¤ What to Do Without Windows? ¤ ‘scp’: Secure Copy ‘scp source-file destination-file’ ¤ If it’s a remote location, don’t forget the ‘:’ ¤ ‘cp’ is the less secure version of this ¤ ‘touch’: Create an empty file ¤ ‘mv’: Change the name or location of a file Careful! This can clobber ¤ ‘lpr’: Print the file, like on archaic paper your files!

  7. Working with Files ¤ ‘grep’: Search filenames and contents ¤ You’ll use grep like a verb, it’s very versatile ¤ ‘head’ and ‘tail’: Display the first or last ten lines of a file ¤ ‘sort’: Sorts a list alphabetically or numerically and removes duplicates ¤ ‘uniq’: Removes non-unique entries from a sorted list ¤ ‘diff’: Identifies the differences between two files ¤ ‘file’: Summarizes file contents, without opening them ¤ ‘echo’: Displays text, or allows it to be appended/redirected ¤ ‘date’: Displays the current date ¤ ‘script’: Records your session

  8. Working with Files: Try This ¤ Start with a list of things (maybe citrus fruits), in no particular order, that contains non-adjacent duplicates ¤ touch citrus.txt ¤ Creates an empty file ¤ echo **paste your list here** > citrus.txt ¤ Adds the text to the file ¤ sort -u citrus.txt > sorted.txt ¤ Sorts and removes the duplicates ¤ diff -u sorted.txt citrus.txt ¤ Displays the changes between the two files

  9. Communicating Between Processes ¤ Using the Pipeline ¤ It’s a pun, just in case you didn’t get that, we’re talking about the straight line character above the backslash. ¤ It removes a lot of intermediary steps by allowing one utility to push data into another, without saving it to a file ¤ Like this: This kind of thing makes the last exercise a lot simpler by removing a step in the middle.

  10. File Compression Utilities ¤ File Compression: More Than Just Zipping Up ¤ Each compression utility has different features and is sometimes not compatible with others ¤ Archiving and compression are completely different features ¤ Archiving puts numerous files together into a package ¤ Compression reduces storage size by efficiently coding it ¤ bzip2, zip and gzip are common compression utilities ¤ bzcat, bunzip2, unzip and gunzip for decompression ¤ tar makes a good archive that preserves file permissions ¤ -c: Create -v: Verbose -f: to File -t: Table -x: eXtract

  11. File Compression Utilities ¤ Trial Run ¤ This illustrates archiving and compressing the citrus.txt file, and then putting it right back where it came from:

  12. Displaying User and System Information ¤ More Useful Utilities ¤ which: The utility’s file PATH (important for shell scripting) ¤ whereis: Every file location of the utility ¤ who: Users on the system ¤ uptime: System uptime ¤ w: Uptime, who and more data ¤ free: Available RAM ¤ write: Send a quick message ¤ mesg: Enable/disable messages sent with ‘write’ utility ¤ w3m: Text-based web browser

  13. ¤ Some Simple Demonstrations:

  14. Summary ¤ Special Character – Syntax Revisited ¤ Basic Utilities ¤ Working with Files ¤ Pipelines ‘|’ Communicating Between Processes ¤ File Compression Utilities ¤ Displaying User and System Information

  15. Exercise ¤ Try this out: ¤ Use w3m to download a web page ¤ Send its text only output to a file without a text editor ¤ scp that file to another folder ¤ tar it ¤ gzip it ¤ write a message to a friend to tell them why you love bash

  16. Work Cited ¤ Sobell, Mark G. ”The Utilities." A Practical Guide to Linux Commands, Editors, and Shell Programming . Upper Saddle River, NJ: Prentice Hall/Pearson, 2013. N. pag. Print. ¤ Wikipedia . Wikimedia Foundation, n.d. Web. 21 Dec. 2015.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend