Unix secrets!

0

Posted in

Secrets of Unix:

Since many people have asked me about some neat command line UNIX tricks, I've decided to compile them together into a webpage. Actually, these are "secrets" for tsch, which is a popular UNIX shell (most commands will work equally well on csh, its predecessor). Also note that versions of programs differ among UNIX systems, and some of the commands may not work exactly as I have described them on your system.

This isn't a comprehensive introduction to UNIX, but rather a collection of little known features that can enhance one's experience in a multi-user UNIX environment, such as is found on most college campuses. This does not replace the manual pages (type "man commandname" at the UNIX prompt) but serves to make people aware of first the existence, and second the general utility, of some commands.

The commands are grouped into several basic categories, and I would also recommend that you take a look at the section on login scripts and aliases for some examples.
Multi-user Communication
E-mail
Remote Communication
Text Editing
Web Browsing
Process Management
Symbols
Miscellaneous
fas.harvard.edu only
Aliases
Friends Script
Login Script
Other Resources

Multi-user Communication:

finger

finger username gives you specific information about a user, including his real name, home directory, and .plan file, if one exists. If the user is logged on, finger will tell you from where he is logged on and how long he has been idle. If the user is not logged on, finger will return the time, date, and address of his last connection. If you just type finger you'll return a list of all users currently logged on to the system. Sometimes users may set preferences to block being fingered, but finger | grep username will allow you to see if they are logged in nonetheless. A neat trick is to set up a text file named .friends with each of your friends' usernames on a new line, and then type finger | grep -f ~/.friends to see which are of your friends are logged in all at once.

last

last username tells you when (and from what address) a user last logged on and when they logged off. Generally the system will recycle the log after a period of days, such as week. Note carefully that only a system with multiple physical machines (for example fas.harvard.edu actually refers to ten physical machines, is01.harvard.edu.edu to is10.harvard.edu, to better distribute the load) last will provide you with information only from the machine which you are currently logged on to. Finger will tell you what machine they last logged on to.

who/rwho
who shows a list of all users logged onto your machine, and rwho shows a list of all users logged onto machines connected to the same local host. In the case of fas.harvard.edu, for example, who shows a list of all users logged onto the same physical machine, while rwho shows a list of all users on all of the ten Harvard IS machines. Type rwho -a to list users who have been idle for more than an hour. Generally finger is more useful, but rwho counts idle time in a generally more useful way.

w

w username tells you what programs a user who is logged into the same physical machine is currently running. Generally, you'll find more information from ps -u username instead of using w.

.plan

The .plan file is a text file in that you can create in your home directory. If it exists, it can be displayed when a user fingers you. Users often put additional contact information in their .plan files, or what they working on at the moment, or a bit of humor. Be sure that the permissions are set correctly so that other users can read your .plan file.

talk

talk username lets you invite another user to chat interactively with you. The user must be logged in, of course, but also must be on the same physical machine. Thus you may finger a user to determine if they are logged in, but when you use the talk command, it may say that the user is not logged in. Look carefully at their finger information, and use talk username@host, where the host is given by the finger command. Then you can invite them to a chat. Of course, the user must accept your chat invitation. Unlike some instant messaging services, talk is real-time, so your keystrokes are transmitted as they are made. It's often good protocol to "double-space" your chat to make it easier to read, and you can periodically clear the window by holding the key. Quit the chat by + (often written as ^c)

ytalk

ytalk is a variant of the talk program that allows multiple users to participate in a single chat. Invite multiple users by entering ytalk username1(@host1) username2(@host2) etc. You can, of course, omit the host if you are all on the same physical machine.

write

write username(@host) lets you write a message on the following lines and send it as a quick "pop-up" message to a user. Terminate your message with ^c

ph

ph is a very powerful program that lets you look at the phone directory on your system so that you can use one piece of information about a user to find other information. Most often you know the real name of a user, and want to find their e-mail address, physical address, or telephone number. If you know the person's exact name, you just type it in, although you'll get more nicely formatted output if you type query realname at the ph> prompt. Sometimes you may not know his entire name, and so you can use the standard * (many characters) and ? (single character) wildcards to help narrow your search. Sometimes the search can be finicky, so if you're not finding the person you are looking for, be creative, and try possible alternatives (e.g. joe, instead of joseph) or widen your search with more wildcards. If you type fields at the ph> prompt, you can also get a list of indexed fields. To search for someone by their email address for example, type query email=username@host at the ph> prompt. Systems may use slightly different names for fields, and not all fields are indexed. Some implementations of ph require you a enter a query mode, by typing query at the ph> prompt, and some will you to modify your own directory information by logging in, and editing fields.



E-mail (using pine):

pine

pine is a very full-featured text-based e-mail program. This section enumerates some useful features that many users may not know about. While some are seduced by the graphical interface of POP/IMAP clients such as Eudora (or, yes, even Outlook) pine holds a number of advantages, especially on a college campus. If you check your e-mail from multiple computers, running pine ensures that you have all of your e-mail available from any location. Furthermore, unless you download and run a suspicious file, using pine renders you impervious to e-mail viruses. Pine is a powerful program, and generally quite easy to use. You start it from the shell prompt with the command pine, although some prefer to begin pine with immediately opened to their inbox, which can be accomplished by typing pine -i

nfrm

nfrm is a sometimes finicky command that tells you whether you have any new mail, and if so it will print the sender and subject. This can let you check to see whether you really want to read your new mail right away without actually opening pine. You might find that the command nfrm -s unread is more reliable.

rich headers

When composing a message, if your cursor is in the header area (the To, Cc, Attachment, Subject area) pressing ^r (remember, +) Will activate the rich header. The most important addition is the Bcc, or blind carbon copy field. Entering addresses in this field will all you to send mail to these addresses without them knowing that the other addresses in this field have also received the message. They will still see the To and Cc fields, however. As a courtesy, the Bcc field should be used when you are sending to a large list—not for secrecy, but because no one wants to read tens or hundreds of e-mail addresses. With the rich header, you can also control which folder the message will be copied to when it is sent (Fcc) among other things.

address book

Having an address book can be a useful feature in pine. You can make both individual entries so that you don't have to remember complicated usernames, as well as making lists of users (e.g. chemistry study group, office-mates, etc.) so that you can easily send to a group. Make changes to the address book from the main menu of pine (press from the inbox) and you can enter names from the address book either by typing the name or nickname directly into the To, Cc, or Bcc fields, or type ^t to choose from a menu.

attaching files

It is often very useful to attach files to e-mail messages. You can easily attach any file in your home directory (or a subdirectory) by either typing in the exact name of the file (case-sensitive) into the Attachment field, or type ^t (when the cursor is in the field) to choose from a menu. You can attach multiple files, and you can easily delete a file you mistakenly attached by moving the cursor to the attachment line and type ^k. Another very useful, but little known feature, is the ability to insert a text file directly into the body of a message. When the cursor is in the body of the message type ^r and then enter the file name or type ^t to choose from a menu. This is really useful, because you can store frequently used bits of text in files in your home directory and insert them very quickly.

editing features

The pine editor (pico) is fairly powerful, and has a number of time saving features. You can delete an entire line by typing ^k, and you can delete multiple lines by holding down this keystroke (be careful!) Actually, the text isn't really deleted, but stored in a temporary buffer, and you can "paste" it back into the message by typing ^u. You are free to move the cursor around, and continue to type in between "cutting" and "pasting" but be careful not to remove more text with ^k before using ^u if you want to save what you previous removed. Sometimes the text is a paragraph will break in an odd way after you've had to make changes, to typing ^j when the cursor is in a paragraph will rearrange the text so that it is nicely justified. Just be careful, for this command can also destroy careful formatting of lists, computer code, or any other text that isn't standard prose. ^a will move the cursor to the beginning of the current line, while ^e will move it to the end of the current line. ^y and ^v will page up and page down respectively. You can also use ^l to redraw the screen (useful when pine interrupts your composition with a new message arrival or chat request). And while everyone knows you can attach files to a message with pine, you can also insert a text file in the body of a message with ^r, which makes a useful way to compose many messages with the same text is part of a message (i.e. save the body of the message to a text file and write a personal greeting to each recipient in the body and then insert the text file.

spell checking

Most versions of pine also include a spelling checker, which can be accessed with the ^t command when the cursor is in the body of the message. The default spelling checker, spell, will identify misspelled words, but you will have to provide a replacement, or ignore the word. Often, correcting a misspelling can change the flow of the text in a paragraph, and so the ^j command is useful to reformat the text. If your system includes the ispell program, you can setup pine to use this spelling checker by default, which allows you to have a customized dictionary of words, and will suggest spelling replacements. To enable ispell is quite simple: go to the main menu of pine by pressing then for setup and for config, then press to search, type "speller" and enter "ispell" into the field.

postponing

Conveniently, pine allows you to postpone messages as you are composing them, to return to them later. Press ^o when composing a message to postpone it. When you try to compose a message again (by pressing c from the inbox or main menu) you will be prompted to either resume a postponed message or start a new message. You can postpone many messages. Sometimes your composition can be interrupted, such as by a network or computer problem. Pine is almost always able to automatically save the incomplete message, and if any such messages exist, you will be asked to resume them in the same manner when you next compose a message. Not resuming a message does not delete it, but just postpones it again.

flags

When a message first arrives it will have a New (N) flag. When you open the message the N flag will disappear. When you reply to a message it will have an Answered (A) flag. When you delete a message it will have a Deleted (D) flag, until you actually exist from the folder, when such messages will be deleted. You can manually change the flag of a message by pressing <*> in the message list, and then following the instructions at the bottom of the screen. Sometimes it's useful to keep the New flag on an important message that you want to remind yourself to reply to. You can also quickly remove a deleted flag by pressing while the message is selected. Incidentally, if you've ever wondered what those plus signs are doing next to some messages at the far left, that means that the message was directed directly to you, as opposed to being sent to you as a carbon copy.

saving attachments

When you receive a message with attachments, you can press v to view the attachments, and then s to save the attachments to your home directory. You can then work with them on Unix, or download them via ftp onto another computer. Sometimes you want to save a message, but not its attachments, because they are so large that they take up your disk quota. To delete the attachments first press v to view the attachments, and then select one, press d to add a deleted flag to it, then press < to return to the main message view, finally press s to save the message, without the deleted attachments, in any of your mail folders. This is also useful for messages copied to your sent-mail folder that have large attachments.

folders

It is often helpful to set up different folders to organize your mail. From the main menu you can view the folder list, and easily add or delete folders. It's often a good idea to periodically move old messages from your inbox into a saved mail folder, so that your inbox doesn't become too large (if its too large, it's prone to corruption, and pine will run very slowly). Thousands of messages is probably too large.

selecting

From a folder view the select command, accessed by pressing <;> can be very helpful. You can select all messages in a folder received before a certain date, for example, and then apply various commands to them by pressing a. For example, you can delete them all at once, save them to a saved-messages folder, or perform other tasks.

searching

If you're looking for messages sent by a certain person or about a certain subject, you can use WhereIs command to search in the folder view by pressing , and then entering a string to search for and then . You can repeatedly search by pressing and as pine will automatically continue your last saved search.

sorting

Sometimes it's easier to resort your messages rather than searching for a particular name. This can be easily accomplished with the <$> key, followed by a choice from the list at the bottom of the screen. The default sort is by date, and this is preferable in general, but it can be useful to temporarily sort by the sender or subject, for instance. If you're close to your disk quota it's helpful to sort by size so that you can either delete the largest messages, or just delete the attachments! Don't forget to revert to sorting by date when you're finished.

signature

Many people like to put a signature at the bottom of each of their e-mails. You can get pine to automatically add whatever text you choose to the bottom of your e-mails by going to the main menu, press for setup, and then for signature. You edit your signature just like composing a mail message, and save the changes.

preferences

There's more, however, to the setup options than just setting a signature. Many of these options are somewhat obscure, but there are a few that may be particularly useful. The first field you'll see is your own name, which is what people receiving your message see. It's good to actually have your full name, and properly capitalized to look professional. If you're sending out messages on behalf of a group, you might want to temporarily change your name (your e-mail address will stay the same, of course), but remember to change it back! You can also set an alternative program to function as your spelling checker, which is a good idea if your system includes the ispell program. Some people like their messages to automatically move to new folder when read, and so you can setup a Read-Message-Folder. Some people find it annoying that pine asks whether you really mean to quit, so you can toggle the quit-without-confirm option. You can also set the ^k command to cut from the cursor position to the end of the line, rather than an entire line with the compose-cut-from-cursor option.

spawning lynx

If you'd like to be able click on url links in html mail that you receive, pine can be set up to automatically spawn a web browser of your choice (generally lynx, unless you're using X-Windows). From the pine main menu go to the setup and config sub-menu (as above). Use a whereis query to find "url" and check "enable-msg-view-urls" and "enable-msg-view-web-hostnames" At the very bottom of the list you can specificy a url-viewer-application, which should be the full path of lynx (type which lynx at the shell prompt to find the full path). After saving the changes, you should be all set, although ocaisonally this feature fails to work on systems that setgid pine. You can get around this problem by runing pine in a different enviornment along the lines of alias pine 'env SHELL=/bin/sh pine'



Remote Communication:

telnet

telnet is a basic program that allows you to connect to remote machines that accept telnet protocol logins. Because telnet does not encrypt passwords, many sites do not accept telnet logins since they are afraid of password sniffers that allow malicious use of accounts. This is actually a very small problem for individual users, and shouldn't worry you when you login to a site via telnet, but explains why some administrators disallow telnet access, in favor of secure protocols, such as ssh. Of course, when you telnet to a site, such as library catalog, which doesn't require a password, there is absolutely no danger! To connect to a particular host type telnet hostname. Ordinarily you end a telnet session by gracefully exiting from the remote machine, although you can always type ^] to enter the interrupt mode, from which you can quit a session.

ssh

ssh is essentially the high-security cousin of telnet. Where possible, you might as well use ssh to connect to a remote machine. The syntax is ordinarily ssh hostname, but the default is to assume that your current username is to be used as the username for the remove machine to which you are trying to connect. Since this is not always the case you can type ssh username@hostname instead to connect to a remote host with a different username. The first time you try to connect to a remote machine with ssh you'll received a "Host key not found from database" message, and a prompt to continue connecting, which you can respond to appropriately.

ftp

telnet is a basic program that allows you to connect to remote machines that accept file transfer protocol logins, and then transfer files and/or directories back and forth. Like telnet ftp does not encrypt passwords, and so many sites no longer allow ftp logins. The basic syntax is ftp hostname and you are then prompted for a username and password. Anonymous ftp sites, such as public domain software repositories allow any user to connection with the username anonymous and any password (sometimes your e-mail address). Other ftp hosts require a username and password to be prearranged—if you have telnet access to the host the username and password are almost certainly the same. You can list the contents of the remote directory with the ls command, and download files from the remote directory to your local working directory with the get command for a single file, or the mget command for multiple files that match a pattern. Likewise, you can upload a file from your local directory of the ftp site with the put command, or the mput command for multiple files. If you want to upload or download a file with a space in its filename, enclose the filename in quotes. You can change the local directory with the lcd command, and the remote directory with the cd command, and type quit to exit.



sftp

sftp is bears the same relation to ftp as ssh bears to telnet. When possible, or required, use sftp to transfer files between hosts. You can logon to remote machine with the syntax sftp (user@)hostname and will be prompted for a password. Other commands are identical with ftp.

scp

scp is the poor man's sftp, and can be used to copy a specific file between hosts. It can be more difficult to use than the interactive sftp, although for certain automated tasks, scp is more suitable.



Text Editing:

pico
pico is a general purpose editor that is very easy to use. If you've ever used pine to compose e-mail, then you've actually been using pico. It's also helpful to look at this nice list of the keyboard shortcuts for pico.

emacs

gnu emacs is an editor of immense power and complication—other than the fact that they both can be used to create and edit text files, emacs is everything that pico is not. An introduction to emacs won't even be attempted here, save for two points: ^h t will start the excellent emacs tutorial, and ^x^c will quit the program. If you're using an x-terminal, you may want to try launching xemacs, although even ordinary emacs will have some graphical elements when opened on an x-terminal. You can also install emacs or xemacs on your windows machine.

vi/vim

vi is another common Unix text editor, and vim is often found in Linux. It is also a powerful editor, with two-modes, an editing mode and a command mode. It is also quite complex, but emacs is a much better editor! Alas, if you insist upon using it, a short list of commands should get your started.

ps2pdf/pdf2ps

Since many people do not own the full version of Adobe Acrobat, software that allows you to creative PDF (portable document format) files that are readable (and look the same) on any machine with Acrobat Reader (almost every computer!), being able to create PDF files nonetheless is very helpful. Proprietary formats, such as Microsoft Word are unacceptable for transfer to other people (and platforms) as they may not have the required software, the same fonts, and the document may not appear the same anyway. By printing your document from any application to a file using a PostScript printer driver you can make a PostScript (.ps) file that can be converted to a pdf file with the syntax ps2pdf orig.ps new.pdf The reverse process can be accomplished with the pdf2ps command, which can be useful if you want to send a pdf file directly to a PostScript printer without viewing it first.

enscript/ps2ascii

The enscript command lets you create a postscript file directly from ascii text, which can be useful if you want to send the text to a PostScript printer. The ps2acsii command distills acsii text out of PostScript file, which can be useful for quick searching or viewing.

acroread

When using the X-Windows graphical interface, the acroread command will invoke the graphical viewer for PDF files.

gs

gs stands for ghostscript, which is an extremely powerful and versitile program for working with PostScript and PDF files. It can be invoked graphically under X-Windows, or specific operations can be performed on files with the command line.

more

more filename allows you to quickly view the content of a file in plaintext one page at a time. It is often useful to pipe the output of a command to more; for example ls | more will list the contents of the current directory one page at the time.

cat

cat filename writes the output of a file in plaintext all at once. Often, more is preferred because it will pause the output when it reaches the end of the screen, but there are also many times when you want to view a file all at once, perhaps because you want to use a terminal program to scroll up later, for example

less

less filename allows you to quickly view the content of a file in plaintext one page at a time. It is similar to more, but incorporates a plethora of additional features, particularly being able to scroll backwards as well as forward in a file. It is most useful as a quick way to look through a very large file, since the entire file doesn't have to be loaded, but generally if you're going to spend the time to use less, you might as well load an editor!

head

head filename allows you to quickly view the first ten lines of a file. You can view any number of lines by head -numberoflines filename, so head -14 foo.txt will show the first fourteen lines of the file foo.txt

tail

tail filename allows you to quickly view the last ten lines of a file. You can view any number of lines by tail -numberoflines filename, so tail -14 foo.txt will show the last fourteen lines of the file foo.txt While this is exactly analogous to head, tail does incorporate an additional very useful feature; tail can also be used to display rest of the file after a certain number of lines. Often files contain headers that it is cumbersome to display, and so tail +14 foo.txt displays foo.txt from the fourteenth line until the end of the file.

wc

wc filename will count the number lines, words, and bytes in a file. wc -w filename will count just the number of words, which can be useful when editing long documents.

banner

banner is a quick little utility that creates so-called "banner text" which is a form of ASCII art. Basically, it's a way to make realy big text display on a text-only terminal. Sometimes people want to use it in e-mails or a talk-session (works better with ytalk!) but often it's most used for leaving a message on your screen along the lines of "Don't touch this window!" banner text will create some banner text, and banner a few words will create banner text of "a few words" on separate lines, while banner "a few words" will create banner text of "a few words" all on one line. Be careful about trying to force too much onto a single line—if you exceed the width of the terminal, banner will start wrapping the text around, which becomes unreadable. You can mix and match—strings bounded by quotes will be written on the same line, and any strings separated by spaces will be printed on seperate lines. If you want to use some unsual symbols, you might have to preceed them by a backslash, for example banner !! will try to make a banner out of the last command entered, but banner \!\! will make a banner out of two exclaimation points!

spell/ispell

spell filename will identify possibly misspelled words in a file. If you're system includes the ispell program use it instead, as will allow you to interactively make changes to the file, in addition to suggesting replacements, and allowing a custom dictionary.



Web Browsing:

lynx

lynx is a very powerful text-only browser that can be run from the command line terminal. You can go directly to a site by invoking lynx address, or by pressing when already in lynx to go to a new address. You can page through text with , access the history list with , and scroll up and down through links with and and move back and forth through hyperlinks with the and lynx supports many features, such as forms and frames, but does not support javascript, https (secure pages), or, of course, images. Lynx is extremely fast, and can be useful to download files that might otherwise automatically spawn an external viewer on other browsers (for example RealAudio (.ra) will generally spawn the RealPlayer viewer on standard browsers, but can be easily downloaded, without modifying your normal browsing preferences, with lynx). Remember that when you connect to a site with lynx the remote site sees the ip address of the machine that you are logged on to, so if you need to access resources restricted to a certain set of ip addresses (such as certain library resources) this can be useful.

netscape

From the X-Windows interface, you can run the netscape browser to browse the web with images. If you want to be able to use the shell window from which you run netscape, type netscape& to run it in the background.



Process Management:

ps

ps shows you a listing of all processes active, including the process identification number (PID). Sometimes it's useful to use the type ps -u yourusername to see all of the processes you have open, especially if you were disconnected from a previous session but left processes hanging.

kill

kill PID# allows you terminate a stalled process from the shell. If there is no ambiguity, you can also kill a process by typing kill %programname, so if I only had one instance of the man process running, I could kill it by typing kill %man without having to use the ps commmand to find its PID#.

jobs

jobs gives you a listing of all the suspended and active jobs running

^z

In many programs ^z allows you to suspend a job as it is being run, to return to later.

fg

fg allows you resume a job that has been suspended (put it back in the foreground).

bg

bg allows you to run a job in the background, so that the shell can be used for other tasks as the job is being processed.



Symbols:

&
Placing the symbol & after a command runs the job in the background, so that the shell can be used for other tasks as the job is being processed.

\
The backslash character removes an special meaning from the character that follows it. For example, more test test.txt would produce an error, but more test\ test.txt would display the contents of the file "test test.txt"

|
The vertical bar character represents the very important pipe command. This command allows you to redirect the output of one command immediately to another. For example, to display a directory listing one page at a time the command ls | more can be used. Pipe has a myriad of uses, and is often used fruitfully to pipe output from commands that produce output in some way to commands that filter or process output.

>
The > command can redirect the output of a command to a file rather than to the screen. For example, to redirect a directory listing to the file dir.txt type ls > dir.txt

>>

The >> command allows you to redirect the output of a command to be appended onto a preexisting file. If you also wanted to store the listing of another directory in the same file above, you could type ls subdirectory/ >> dir.txt
;

The semicolon symbol can be used to separate commands entered on the same time. For example, if you wanted to write the time and date to a file, and then append to it the listing of directory contents, the following command could be written on a single line date > dir.txt ; ls >> dir.txt, where the spaces are added for clarity alone.
^

The carat symbol can be used to repeat the previous command while changing part of it. For example, if you first type more test.txt to view the contents of the file "test.txt" and then want to open it with the pico editor, rather than retype the entire line you can simply type ^more^pico and the shell will print the command pico test.txt to the screen and then execute the command. This can be a real time saver.

~
The tidle symbol represents your home directory, and so allows you to quickly access your home directory no matter what directory you happen to be in, just as the forward slash character allows you to easily access the root directory.

!
The exclaimation point can be used to recall previously entered commands. For example !! will recall the last command entered, !-3 will recall the third to last command, !more will recall the last command that began with the string "more" By using the colon along with the exclaimation point you can recall individual words from previous commands. This can be quite powerful, as you can string commands together to create new commands, so !-10:4 | !:2 !-3:$ | !-5:0 executes the fifth word of the tenth to last command and pipes it to the third word in the last command operating on the last word in the third to last command piped to the first word (the command itself!) in the fifth to last command. Whew.

..
Two periods represents one directory level up from your current location, so if you are in /users/username are type cd .. you will be in /users

^c
The + combination is a common interrupt for many processes in Unix.



Miscellaneous:

auto-completion

Because it can be a pain to type (or just remember) long file names or commands, it is very useful to let the shell auto-complete where possible. After having typed in part of a filename or command press (in some shell versions press ) and the shell will attempt to auto-complete. If multiple files match the initial pattern, a list will appear, and you can type additional letters and press again to narrow the list, or complete the name.

math
On systems that have Mathematica™ installed, you can type math at the shell prompt and start terminal graphics session. Rather than the full notebook interface that you may be used to, the front-end executes commands as they are typed sequentially. Even with a less flexible front-end and with a text-only display, the power and beautiful of Mathematica™ is awe-inspiring. At Harvard, you need to log into an ice.harvard.edu machine in order to run Mathematica™. Rumor has it that a so-called competitor to Mathematica™ can be run by typing matlab at the shell prompt from some machines, although why anyone would want to use such a program remains a mystery to me.

history
You can view the history of the commands that you've entered in this session with the history command. You can enter a particular command by typing !commandnumber or press to scroll through the list of the previous commands from last to first. You can use the -c switch if you want to clear the history list.

set prompt

You can reset the default prompt with the command set prompt="new prompt " Although it is not required, it is a good idea to end the new prompt with a space for readability. Some people find it useful to include the string \! in their prompt, as this displays the command number on each command line, so that you can easily return to it with a ! command. You can set the prompt to include the time with the sequences %t, %T, %p, %P, or the day (%D), month (%W), or year (%y). You can also the set the prompt to display your current directory location form the root (%/%) or your home directory (%~%). You can also set the prompt to display the hostname (%m) of the machine to which you're logged in. Setting these attributes may serve as a useful reminder.

set term
You can set the terminal emulation with the comand set term=terminaltype command, where common terminal types are vt100, xterm, and so forth. This can be necessary for the keyboard and display to function properly in certain programs, such as emacs and lynx.

grep
grep is an extremely powerful searching command that returns all lines of a file or output that match a given pattern. grep is often fruitfully paired with the pipe (|) command; for example, ph name | grep telephone will first query the ph database for the directory information on the given name, and then pipe the output directly to the grep command (before it is displayed to the screen) which will return only the line or lines that begin with the string telephone.

chmod

chmod is a powerful command that allows you to alter the permissions for files and directories. When you look at the long list of files in a directory (ll or ls -l) the first column will contain seemingly cryptic strings such as "-rw----r--" or "drwx------" These strings are ten characters long, where the first character denotes the file type: "-" for a normal file, "d" for a directory, and several other characters for other special file types. The next block of three characters contains the read, write, and execute permissions for the owner (seen in the third column of the long file list), then the next three for members of the owner's group (seen in the fourth column of the long file list), and the final three characters contain these permissions for the world. So the first string above shows a file that the owner can read and write, and anyone else can only read, while that second string shows a directory that the user can read (i.e. list the contents of) write to, and execute (i.e. cd to). You can change the permissions of a file that own by typing chmod who±function file, where who refers to yourself (u), members of your group (g), everyone else (o), or everyone, including yourself (a), ± is either a + or - depending on whether you want to add or remove the permission, the function is either read (r), write (w), or execute (x) and the file is the file (or pattern) you want to apply the change in permissions to. chmod is a powerful tool: you might use it to give a friend access to a particular file or subdirectory, or to make your .plan file readable by anyone. You can also remove the write permissions of a file to make sure that you don't accidently change it. But making your inbox or home directory readable by anyone is strongly not recommended! Some people find it easier to use the octal syntax with chmod, where permissions can be set by typing chmod ### file where the first # refers to the permission for the user, the second for the group, and the third for the world, and is the sum of read=4, write=2, and execute=1, which makes a unique sum for between 0 and 7. Thus to set the permissions of the file test.txt to "-rxw-w-r-x" you could type chmod 725 test.txt

date
date displays the current date and time. There are many options for this command that control precisely how the date and/or time are formatted. A few particularly useful combination, and examples out their output are shown here: date +%k:%M:%S might return 14:11:40 while date +%l:%M\ %p might return 2:11 PM. And date +%A,\ %e\ %B\ %Y might return Sunday, 2 June 2002, while date +%D might return 06/02/02. See the manual page for all options.

cal
cal simply displays a (standard Gregorian) monthly calendar for the current month, while cal year displays the monthly calendar for every month in the specified year, and cal monthnumber year displays the monthly calendar for the given month in the given year.

calendar
The calendar program reads the calendar file in your home directory and outputs any events/tasks that match the current date. For more information on the structure of the calendar file, see the man page for this command. If you actually keep a calendar file (good for birthdays and other long-term, enter-once, repeating events) you might want to place this command in your login script.

sleep
sleep is a simple program that pauses for a certain number of seconds. The following example shows one possible use: sleep 600 ; echo "Time to go to class!" & That is, in ten minutes the shell will print "Time to go to class! while the sleep program runs in the background.

which
which commandname tells you the actual location of the command that you are running. Sometimes an application wants to know the full path of a command, and sometimes you want to see if a different version of the command or application is available. On fas.harvard.edu most programs can be found in /usr/local/bin

clear
clear simply clears the screen, which can be helpful to reduce clutter.

fortune

fortune is a cute program that returns a random "fortune" from a large database. If you want to cheat fortune -m pattern returns all fortunes that contain the pattern.

pwd
pwd stands for "print working directory" and will output the current directory. This can be useful when you're wondering why a file isn't there (you may be in the wrong directory) or are just lost navigating through the file system.

whoami
whoami is a simple program that prints your own username. This is useful when you are at a computer or terminal where someone else has logged in, and you want to see whether you can log him out (you're his boss) or you shouldn't (he's your boss).

zip/unzip

These commands allow you to make compressed pkzip archives, or decompress pkzip archives. The pkzip format is a standard compressed format used primarily on the MS-DOS/Windows platform. Remember that if you ever are using a PC that doesn't happens not to have a program that can unzip a file, you can always upload the file to a Unix machine and unzip it, and then download the unzipped files, although it's actually better to zip files that you want to download first--not only will they download faster, but you won't have to worry about ASCII/binary format problems. zip is a very useful program for other things; you can use it to make a downloadable archive of all of the files in your home directory by typing zip -r /scratch/username/archive.zip ~/ remembering to first create the directory by mkdir /scratch/username or where ever else you might have temporary space. Don't worry if it takes some time to create the zip archive.

tar

The tar (Tape ARchive) command allows you to create a tar archive out of multiple files, or unpack a tar archive into multiple file. tar archives are not compressed, but are a convenient way to transfer groups of files, without taking the time to compress and uncompress them (especially if they are already compressed, such as jpeg or mpeg files!)

gzip/gunzip
gzip creates .z archive files compressed with Lempel-Ziv encoding, and gunzip can uncompress archives created with gzip, as well as other .z archives created with compress and pack, as well as pkzip files. gunzip is a very versatile program

uuencode/uudecode
uuencode allows you to encode a binary file so that it can be transmitted as ascii data, and uudecode allows you to decode a uuencoded acsii text string back into binary data. Sometimes you might receive a uuencoded attachment, or need to send a binary file (e.g. an executable program) as an ascii file.

man
By typing man commandname at the shell prompt you can get complete information about any of the commands listed above, as well as many more. The manual pages are essentially help files, and are very useful. Most manual entries will have a brief description, a listing of options (especially switches, which modify the behavior of a command and are preceded by a "-"), and some examples.



fas.harvard.edu only:

fixwebfiles
fixwebfiles is a macro that automatically sets the permissions to your public_html directory so that a webpage that you create there an be viewed by anyone.

fixfinger
fixfinger is a macro that automatically sets the permissions on your .plan file so that it can be viewed when you are fingered.

termbill
termbill is a program that lets you add money to your printing balence by charging your termbill a preset amount. It is often easier and generally more convenient to add money your printing balance with this program, than with a Crimson Cash machine, although the funds won't be added immediately—there's usually a fifteen minute delay.

weather
weather is a neat little script that will automatically telnet into rainmaker.wunderground.com, and pull down the current weather and forecast for Boston, Massachusetts. It's actually not really as fas.harvard.edu only script, but it is preinstalled on fas, and configured for Boston. It's actaully a program in an elegant scripting language called expect, which runs in tcl. It's freely available, along with the weather script which was authored by the creator of the language, Don Libes. You can find information about the language on his website, as well as the actual weather script.

checkquota
checkquota prints out a quick description of your disk quota status.

quota
quota prints out a more verbose description of your disk quota status. quota -v prints out an even more verbose description of your disk quota status, including your use of any scratch space.

scratch (and df)
The scratch disk is a 2 GB disk that is available for any fas user to temporarily store files. You can create a personal subdirectory in the scratch directory by typing mkdir /scratch/yourusername and then you can copy large files into that directory. When you are finished, you should leave the space available for other users by typing rm -rf /scratch/yourusername The scratch disk is useful if you are performing computations that require the temporary creation of large data sets, or if you need to transfer large files between two machines. Files must be accessed at least once every 48 hours, or they will be automatically deleted. Generally, it is a general rule not to leave files in scratch for this long in any event. Also, if you are not currently logged into fas, your scratch space may be arbitrarily reduced to 100 MB, however, if you remain logged in this will not happen. Scratch space can fill up, but you can see how much space remains on the scratch disk with the command df | grep /scratch and plan accordingly. See the fas page on temporary storage as well

Deciphering Harvard ip addresses

So now that you know how to use the finger and last commands, you can see where users have logged on. But sometimes the ip addresses will seem very cryptic, so here's a quick guide to deciphering Harvard IP addresses. It's best to use the so-called "friends script" where you can see a really complete list, and have the computer do it automatically for you, but here's a quick guide:

roam###.###.student.harvard.edu addresses are Harvard dorm rooms, house computer labs, or student laptops that are "roaming"

Addresses that begin sunray are from the SunRay terminals in the Science Center between halls D and C, while those that begin with sc- are from Science Center (basement labs or room 120)

You should also be able to figure out the addresses from the Lamont and Sever computer kiosks which are popular places to login from.

Addresses with a wjh are from William James Hall, the social science building, those with a ccb, are from the Chemistry and Chemical Biology buildings, and so forth.

IP addresses that begin with 128.103.29 are from the Crimson, and those that begin with cust-206-40 are from the Lampoon.

Off-campus IP addresses won't end with harvard.edu or won't begin with 140.247



Friends Scripts:

A handier way to keep track of your friends online involves using a program known as a script. The various friends scripts are written in a scripting language called tcl (pronounced tickle) and are cleaner than piping the output of finger to grep. Basically they run the finger or rwho command, select out the lines corresponding to people in your .friends file, reformat the output, and match the IP addresses to a very extensive list. You can look at some sample output from the different friends scripts. There are instructions for installed the scripts at the top of each of the files.

I am not the original author of the friends script, but I have edited the original script to make several additional versions. When I get a bit of time, I will collapse them back together, and allow a single program to have all of this functionality (and more!) by using switches. Updates for the IP matching table are always appreciated as well!

friends

The friends script is optimized for terminals with wide displays, such as SecureCRT running on a Windows machine (just maximize the terminal window). It shows a lot of information on each line, including the person's username, their real name, which is machine they're logged into, how long they've been idle, and the IP address of the machine they're logged in from, as well as the location.

narrowfriends
The narrowfriends script was created because some terminals are limited to a display width of 80-characters, the narrowfriends script is written to fit within these limitations. It shows the same information as the friends script, but omits the actual IP address. This is usually fine as the most commonly encountered IP addresses are entered into the table.

allfinger
The allfinger script shows information for more than just the people in your .friends file. It's useful because you can manually grep the output to show all people in a particular location, such as one of the houses. This is useful if you want to see who else on your floor is awake. It's easiest to insert the following line in your .aliases file: alias all '~/bin/allfinger | grep -i \!*' and then you can just type all locationname and don't have to worry about the case.

rfriends
The rfriends script is the original "friends script" and uses rwho, rather than finger information to compile the friends list. This has the disadvantage that rwho doesn't include the person's real name, and some find it a bit strange to always see just the username. However, rwho uses what is often a more useful measure of idle time than that in finger—idle time as measured by rwho counts from the last time the user touched the keyboard of his terminal, rather than the last time a program changed something!



Aliases:

alias
The alias command is extremely useful, for it allows you to shorten a frequently used command, or string of commands, to a single, customizable word. The syntax is alias aliasword command For example, if you want to easily be able to jump to a webpage with lynx, you can type alias fas lynx http://www.fas.harvard.edu/ in a single line and then you only need to type fas to execute the command lynx http://www.fas.harvard.edu/

unalias
If you accidently make a word an alias you can type unalias aliasword to restore the original meaning, if any, and remove the alias.

.aliases
The .aliases is a special file that can include a large number of alias lines that will automatically execute every time you login to the system, assuing that the line source .aliases, or an equivalent, is found in your .cshrc file. You can always put the aliases in .cshrc file directly, however, it is often useful to keep a sepate listing. The .aliases file is extremely useful, as you can see a number of useful aliases at one time, and have them automatically ready every time you login.

Comments (0)