UNIX: Sorting & Pipe System
Lecture Overview
This lecture covers fundamental UNIX concepts related to input/output streams, file redirection, and piping between programs. These mechanisms are crucial for creating flexible and modular command-line workflows.
The objective is to combine these tools to create powerful and efficient command-line functionalities by chaining simple utilities.
Useful UNIX Utilities
wc (word count)
Functionality: Reports the number of lines, words, and characters (bytes) present in a given file or read from standard input.
Applicability: While
wccan process any file type, its counts for lines and words are most meaningful for human-readable text files. For binary files, it accurately reports the byte count, but line and word counts will typically be zero.Utility: It's a versatile tool for quick data assessment, text analysis, and scripting, enabling users to gain immediate insights into a file's size and textual structure.
Requirement: By default,
wcreads from standard input (stdin) if no file argument is provided. To operate on the content of a file or the output of another command, it often leverages file redirection (e.g.,<for input from a file) or piping (|) for input from another process.Example Usage:
To view the content of
TextFile, one might usecat TextFile. IfTextFilecontains:Hello world. This is a test. Another line. End of file.
Then,wc TextFilewould output4 13 54 TextFile. (Here,4lines,13words,54characters, assuming standard character encoding and no trailing newlines affecting word count).When attempting
wc /bin/killon a binary executable file like/bin/kill, the output might look like0 0 16864 /bin/kill. This indicates 0 lines, 0 words (as these concepts don't apply to raw binary data in the same way), but accurately reports the size of the file in bytes (e.g., 16864 bytes).