9. Other Useful Commands
finger -m usernameThis information can be useful in reading and sending mail, to determine who sent you a message if the sender is identified only by login name, or to ensure that your own messages are directed to the right person.
If you want to add, delete, or revise information, use the nispasswd program:
nispasswd -gIt displays, information it already has for you. For example, its first line might be
Name [Pat Pending]If ``Pat Pending'' is correct, just press Return. To change it, type the new value and press Return. To remove a value completely, type none and press Return. After you have responded to all the prompts, nispasswd gives the message ``Updating user information'' and exits. It may take one or two hours for the update to take effect.
To use grep or fgrep, give the command
grep [options] expression [file] ... or fgrep [options] [string] [file] ...If you give no filenames, grep and fgrep search standard input (your terminal), and so they can be used at the end of a pipeline of commands (see chapter 4). The grep program expands special characters in the given expression. The fgrep program does not expand any characters, but searches for exact matches of the character string you specify. Normally, both grep and fgrep will search the files you specify and produce a list, on standard output, of every line containing the text string matching the string or expression you specified.
The grep command can expand special characters to find matches in much the way the shell expands special characters in file and directory names. Below is a simplified explanation of that expansion. The term ``special character'' here means one of the seven characters
\ [ ] . ^ * $and a delimiter (such as apostrophe) used to mark the beginning and end of an expression. The delimiters are required if the expression contains any blanks or special characters, and they can be used even if the expression does not contain such characters.
Any nonspecial character matches itself. Thus
grep 'man page' intro.draftsearches through the file intro.draft for all occurrences of the expression ``man page''.
A period matches any character. So
grep 'an.' intro.draftwould find ``and'', ``any'', ``manual'', ``can'', etc. in the file ``intro.draft''.
If a set of characters is placed inside square brackets, each one is considered for matching in that position. Thus
grep '[mh]an' intro.draftwould match any words containing the sequence ``man'' or ``han'', but not ``ran'', ``can'' or `` and''.
You can use the hyphen within square brackets to denote an inclusive range. Thus
grep '[a-c]r' intro.draftwould match strings containing ``ar'', ``br'' and ``cr''.
The character \ turns off the special nature of the character following it, provided that \ is not within square brackets. Inside square brackets, \ is an ordinary character. So
grep 'manual\.' intro.draftturns off the ``special'' nature of the period and matches ``manual.'', but not ``manual '', ``manuals'', or ``manually''.
The fgrep command does none of this expansion; however, you can search for more than one string of characters with a single fgrep command. To do this, place the possible strings, one per line, in a file. Then use the option -f file instead of the string option when you call fgrep, like this:
fgrep -f list intro.draftIf file ``list'' contains
manual. manuals manuallyfgrep would find all lines in intro.draft that contain ``manual.'' or ``manuals'' or ``manually''.
Here are some useful options to both grep and fgrep:
-i Ignores case, so that uppercase and lowercase characters match each other. -n Displays the line number with each line containing a match. -l Displays only the names of files that contain matching lines, but not the lines themselves. This is useful if you are searching through a set of files to see which of them contain a particular pattern. -v Displays lines that don't match a given pattern.
diff oldfile newfileThis produces, on standard output, a list of lines that must be changed (c), appended (a), or deleted (d) to make the first file match the second. Lines from the first file are prefixed by ``<'' and lines from the second are prefixed by ``>''.
If you only want to determine IF two files differ, and not HOW they differ, you can use cmp:
cmp file1 file2The cmp program merely notifies you if the files don't match, stopping its comparison after it finds the first difference.
Note: It is generally not a good idea to transfer binary executable files from one computer architecture to another. Compiled programs will almost certainly not run on the receiving system without recompilation, so you should transfer source files of programs instead.To illustrate a simple FTP session, the following example shows user joey logged in on a Hardlink UNIX system, using FTP to get file cprog.data from Hardlink and naming the local copy of it cdata.sun. What the user types is shown in boldface. Everything else is from the local FTP or, in the case of responses that begin with a number, remote Hardlink FTP.
% ftp ftp> open ftp.hardlink.com (1) Connected to bronco.hardlink.com. 220 bronco FTP server (NcFTPd 1.9.6) ready.. (2) Name (ftp.hardlink.com:joey): joey 331 Password required for joey. Password: xxxxxx (3) 230 User joey logged in. ftp> get cprog.data cdata.sun (4) 200 PORT command successful. 150 Opening data connection for cprog.data (126.96.36.199,3686) (528 bytes). 226 Transfer complete. local: cdata.sun remote: cprog.data 544 bytes received in 0.025 seconds (21 Kbytes/s) ftp> quit 221 Goodbye.
get remotefile localfile
Had user joey wanted to send, instead of get, a file, the command would be
put localfile remotefileBesides the man page, FTP has internal help that provides short explanations of all available commands. In response to the ftp> prompt, type
helpTwo particularly useful commands are mget and mput, which enable you to specify wildcards to get or put multiple files. The FTP program prompts you for each matching file before it transfers it. For example, suppose you have five files that end in .txt on a remote machine, in a large directory, and you want to get only two of those five files. The files are:
Document_list.txt file1.txt file2.txt myfile.txt notitle.txtThat part of your FTP session might look like this:
ftp> mget *.txt mget Document_list.txt? n mget file1.txt? n mget file2.txt? y 200 PORT command successful. 150 Opening BINARY mode data connection for file2.txt (188.8.131.52,2784) (553 bytes). 226 Transfer complete. 553 bytes received in 0.09 seconds (0.011 Kbytes/s) mget myfile.txt? n mget notitle.txt? y 200 PORT command successful. 150 Opening BINARY mode data connection for notitle.txt (184.108.40.206,2786) (227 bytes). 226 Transfer complete. 227 bytes received in 0.065 seconds (0.015 Kbytes/s) ftp>
http://www.hardlink.net/USENET/for more information about USENET news.
A file in your login directory, named .newsrc, keeps track of all the newsgroup names and which messages in each group you have already seen. To read any of these newsgroups, use a news-reading program. One such program is called trn. The trn program examines your .newsrc file and displays unread articles in the same way that more displays a file--one screenful at a time. (Be sure your terminal type is defined correctly--see chapter 2.) When you first run trn, you will be ``subscribed to'' a newsgroup named news.announce.newusers, which contains useful information and guidelines for what is called ``netiquette''--common courtesy to use in posting messages.
The trn program has many more options than can be discussed here-- selecting articles by subject matter, subscribing and unsubscribing to newsgroups, saving articles, and searching for patterns within an article. You can also reply to the sender of an article or post a follow-up message. For a complete description, see the trn man page.
To post your own new message to a newsgroup, use the Pnews program. (Notice the capital ``P''.) It prompts you for necessary information.
Another popular news reader is called tin. It also uses the .newsrc file, but when you first use it, it shows you all available newsgroups--several thousand of them. You can go through the list, or search for keywords in newsgroup names, subscribing to the ones you want. For more information, see man tin.
script filenameNow everything you type and everything displayed on the screen will also be copied to the file filename. To stop the recording, use ^d or exit.
tty ps -u usernameThe first command identifies the terminal you are now logged into. The second shows you all processes you (username) own that are running on the system.
cshin the COMMAND column. These are the top-level login shell processes for your jobs.
kill -HUP pidwhere pid is the process id number you just found.
kill -9 pid
% tty # Determine current login terminal /dev/tty5c # Its TTY number is 5c % ps -u myname # Look at all processes I am running PID TT STAT TIME COMMAND 27595 4a E 0:24 csh # Shell running on another terminal 28200 5c E 0:03 csh 28275 5c R 0:01 ps xg % kill -HUP 27595 # Send that shell a hangup signal % ps -u myname # Check to make sure it worked PID TT STAT TIME COMMAND 28200 5c IW 0:03 csh 28350 5c R 0:01 ps xg
Go to next chapter
Go back to table of contents