Thursday, July 17, 2008

COMMANDSCommands are what you type at the prompt. Com-mands have arguments on which they operate. Forexample, in rm temp, the command is rm and the ar-gument is temp; this command removes the le calledtemp. Here I put arguments in UPPER CASE. Thus,words such as FILE are taken to stand for some otherword, such as temp. In the following list, I use [ ] foroptional arguments that are not typicaly used.Commands have options that are controlled withswitches, which are usually letters following a singledash. Usually you can write several letters after onedash. For example ls -l lists les in a long format,with more information. ls -a lists all the les, in-cluding those that begin with ., which are usuallyles used by various programs. ls -al lists all theles in the long format. The following list omits mostoptions. Many programs will give you a list of theiroptions if you type the name of the program followedby -h or -?.Other options are controlled in special les usu-ally beginning with ., such as .emacs, .mailrc, and.newsrc. You can edit these. The le .cshrc con-tains general options, plus aliases that you make upfor commands you use often.|, the pipe symbol, takes the output of one commandand gives it to the second command as input, forexample, ls -l | more allows you to view a longle list through \more".> directs the output to a le, e.g., ls -l >listing.tmp puts the listing into a le named list-ing.tmp. > overwrites an old le of the same name.>> appends to a le.* stands for any string of letters. For example, ls t*lists all the les beginning with t." recalls previous commands, and you can edit thesecommands using emacs editing.The tab key completes commands if you type the rstfew letters.ctrl-z suspends most programs. fg resumes. ctrl-cstops most programs.alias abbreviates a series of commands, separatedby semicolons. Useful in .cshrc.GETTING HELPapropos KEYWORD: Looks for commands related toKEYWORD.man COMMAND: Shows manual pages on COMMAND.This is the authoritative source on the items de-scribed here. The commands can do much morethan is listed here.whatis COMMAND: Tells what COMMAND does.FILES AND DIRECTORIESAll information is stored in les. File names andcommands are case sensitive. Case matters. Filesare contained in directories. You start out in yourown home directory, and your prompt usually tellsits name. At any given time, one of these directoriesis your working directory, the one you are in.You can refer to les in your working directory byjust their names. You can refer to a le that is in asubdirectory by giving a subdirectory name, a slash,and the le name, e.g., Mail/baron. You can refer toany le on the computer by giving its full name, start-ing with a slash, such as /home7/b/baron/mbox.If the le is a program, typing its name will run it.(That is what commands do.) If the program is some-thing you have just written and is in the director youare in, put ./ before the name. If the le is not aprogram, typing its name will give you an error mes-sage. If you want to see its contents, for example, youmust use a command such as \more" before the lename.ls [DIRECTORY]: Lists les. (Also try: ls -f, ls -s, ls-a.)rm FILE: Removes FILE.more FILE or less FILE: View FILE. (? or h forhelp.)cd DIRECTORY: Change the directory you are in toDIRECTORY.cd: Change to your home directory.cd ..: Change to the next directory up in the hier-archy.mkdir DIRECTORY: Make DIRECTORY.rmdir DIRECTORY: Remove DIRECTORY.rm -rf: Recursively remove a directory and anythingin it.mv FILE1 FILE2: Moves or renames FILE1 toFILE2.cp FILE1 FILE2: Makes a copy of FILE1, calledFILE2.cat FILE1 FILE2 > FILE3: Concatenate FILE1and FILE2, calling the result FILE3.chmod 644 FILE: Unprotect FILE for others to reador copy.chmod 755 FILE: Unprotect program or \script."chmod 755 DIRECTORY: Unprotect DIRECTORY,needed for web page directories.head and tail: Print the top and bottom of a textle.TEXT FILE MANIPULATIONThese commands operate on les. The output goesto the \standard output," which is your terminal dis-play. If you want to \redirect" the output to a le,use > FILENAME at the end of the command (withFILENAME being the name of the le). Use >> insteadof > if you want to append to the le rather thanwrite it from scratch.diff: Find the dierences between two text les.grep LETTER-STRING FILE1 [> FILE2]: Prints (orputs in FILE2) all lines of FILE1 that containLETTER-STRING. Use the -v switch to get linesnot containing the string.sed s/STRING1/STRING2/g: replace STRING1 withSTRING2 throughout a le. See also the y switchfor replacing characters.cut -d" " -f2 FILE: Extract the second columnfrom a le, where the columns are delimited byspaces. Use paste to put such cuttings back to-gether.sort FILE: Sort the lines alphabetically.uniq FILE: Remove adjacent duplicate lines. Typi-cally used with the output of sort, e.g., sort FILE| uniq. Use the -c to count the number of ad-jacent examples of each line.wc FILE: Count characters, words, and lines.WHAT'S GOING ON?w [USER]: Who is using the computer. This is usefulto see whether you are logged on twice. (See ps andkill, below, in case this happens.) Also try who andfinger.finger USER: Gives information about the user, in-cluding the les .project and .plan, if you havethese les. You can sometimes use this for peopleon other computers. You can keep useful infor-mation in your .plan, such as your schedule, yourphone number, etc.quota -v: Tells you how much of your quota for lesis used up.ps -fu USERNAME: Lists the processes that you arerunning, if you put in your username. You can usethis to nd the number of processes that you wantto kill, such as those left over when you did notlog out properly. It is the rst number listed.kill PROCESS-NUMBER: Kills the process you don'twant. If this doesn't work, try kill -9PROCESS-NUMBER.last -22: Shows you the last 22 users who loggedin.THE INTERNETmutt and elm: Read and write electronic mail. Eachhas its own \help". See the discussion of these inthe psychology web page computer section.slrn and tin: Read news (and respond to postings).Pnews: Post to newsgroups. (You canalso say mutt psych-general@psych orelm psych-general@psych to post toupenn.psych.general.)lynx [URL]: Reads web pages as text les.ssh HOST: Connects to a remote computer.talk USERNAME: Allows you to talk with someonelogged on. The full username must be speciedfor remote computers, and you must use ntalkinstead of talk. It is not a good idea to use thiscasually unless you know that the other person willnot be annoyed.TRANSFERRING FILESMany computers on the internet have ftp or ssh, butall of the programs for transferring les depend onhaving the relevant software on both computers.ftp and scp: Fast way of uploading and down-loading, or moving any le from one com-puter to another. For example, scp myfilebaron@psych.upenn.edu: - you need the colonat the end.rsync: synchronize les or directories on two dier-ent computers. Good for backing up.EDITINGpico FILE or emacs FILE xemacs FILE or vi FILE:Edit FILE. One of these editors may be speciedas the default for mailing and news programs. Picois easiest because it has all the commands listed atthe bottom of the screen, but it is the least usefulbecause it has few commands.COMPRESSING, ENCRYPTING, and SE-CURITYtar cvf FILE.tar and tar xvf FILE.tar: Createand extract an archive le. Useful for backing updirectories. On Linux xvfz will extract and unzipin one step.gzip FILE: Reduce the size of les for storage. usegunzip FILE to unzip them. Files \zipped" withgzip have the sux .gz.crypt <> FILE2: Encrypts or decodesle1 so that you need a password to read it. But ifyou want to be absolutely sure beyond any doubtthat nobody will read your les, do not leave themon cattell.antiword FILE1 > FILE2: Decodes a Word leinto text. (That is all most of them are.) Savestorage space. You can use this with Mutt or Elmto read doc les sent in email messages.passwd: Change your password.Jon Baron, September, 2003