The Command Line, Part II, Pine, and Pico CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes. wc (Word Count) The wc command tells us some additional size-related statistics about the file. ls displays the size of the file in bytes wc displays the number of lines and number of words (as well as bytes) Arguments: -c (# bytes), -l (# newlines), -m (# characters), -w (# words) Example using a single file as the argument: linux1-(10:48am): wc file1.txt 80 359 3717 file1.txt Example using multiple files as arguments, separated by spaces. When we switch over to multiple files, wc also reports the grand total. linux1-(10:48am): wc file1.txt hello.c 80 359 3717 file1.txt 20 74 596 hello.c 100 433 4313 total Example using multiple files as arguments, using a wildcard: linux1-(10:49am): wc *.txt 80 359 3717 file1.txt 63 350 2592 file2.txt 63 350 2592 file3.txt 206 1059 8901 total diff (the DIFFerence between two files) In this example, there are two C source code files. There is a slight difference between the 2 files. We will show the contents of each first then use the diff command and let it spot the difference. linux1-(10:55am): cat foo.c /* File: hello.c * Description: This program prints the message "Hello, world.“ */ #include <stdio.h> int main() { printf("Hello, world.\n") return 0; } linux1-(10:55am): cat bar.c /* File: hello.c * Description: This program prints the message "Hello, world.“ */ #include <stdio.h> int main() { printf("Hello, world.\n"); return 0; } linux1-(10:55am): diff foo.c bar.c 18c18 < printf("Hello, world.\n") --> printf("Hello, world.\n"); The UNIX Pipe (|) The pipe (|) creates a channel from one command to another. Think of the pipe as a way of connecting the output from one command to the input of another command. The pipe can be used to link commands together to perform more complex tasks that would otherwise take multiple steps (and possibly writing information to disk). Examples: Count the number of users logged onto the current system. The who command will give us line by line output of all the current users. We could then use the wc -l to count the number of lines... who | wc –l Display long listings in a scrollable page. The lpq command will give us a list of the waiting print jobs. lpq | less sort (SORTs lines of text files) sort arranges lines alphabetically (or numerically with the –n option) Example: Display a sorted list of all users on the computer. Display a list of files sorted in decreasing order by size in bytes who | sort | less wc -c * | sort -nr Other commands which are useful with sort: uniq : removes duplicate adjacent lines from a file Example: sort file.txt | uniq cat -n : prepends line numbers Example : sort file.txt | cat -n pine (Program for Internet News and E-mail) Pine is the University of Washington's "Program for Internet News and Email". It is intended to be an easy-to-use program for sending, receiving, and filing Internet electronic mail messages and bulletin board (Netnews/Usenet) messages. Pine Help: Help can be accessed anytime by typing the question mark character (?). Links for more information about pine: Official Pine Website: http://www.washington.edu/pine/ Pine Tutorial: http://www.washington.edu/pine/tutorial/ Pine Users Guide: http://www.washington.edu/pine/userguide/ Pine Commands GENERAL < and > – general navigation ? – help READING MAIL r – reply f – forward s – save a message to another mail folder e – export the message to a text file COMPOSING MAIL ^r – insert file contents ^t – to files ^x – send message ^o – postpone message ^c – cancel message ^j – justify (while in header) or attach (while in body) ^k – cut line ^u – uncut line Pico Pico is an easy-to-use editor that resembles Pine. Think of it as a simplified version of emacs. Although it lacks most of emacs' sophisticated functions, pico compensates by having virtually no learning curve associated with its use. Unlike emacs, pico is a shell or terminal-based editor only. There are no added benefits of running pico under X window. There is no toolbar, but pico always displays a list of commands at the bottom of the screen. Pico does not have as extensive of a tutorial as EMACS, but it does offer a built in help screen. To access it type ctrl-g. Pico - Reference Card: http://www.cs.umbc.edu/~cshc/resources/new_student/pico_BASICS.shtm l Pico Commands ^G - Display help. ^X - Exit pico, saving buffer. ^O - Saves the current buffer to a file. ^V - Move forward a page of text. ^Y - Move backward a page of text. ^^ - Mark cursor position as beginning of selected text. ^K - Cut selected text. Note: The selected text's boundary on the cursor side ends at the left edge of the cursor. ^U - Paste last cut text at the current position. ^F - Move forward a character. ^B - Move backward a character. ^P - Move to the previous line. ^N - Move to the next line. ^A - Move to the beginning of the current line. ^E - Move to the end of the current line. ^W - Search for text. ^T - Invoke the spelling checker. ^L - Refresh the display. ^J - Format (justify) the current paragraph. ^C - Report current cursor position. ^D - Delete the character at the cursor. ^I - Insert a tab at the cursor. ^R - Insert an external file at the cursor.