Xref: utzoo comp.unix.questions:14105 comp.unix.wizards:16749 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!iuvax!sahayman From: sahayman@iuvax.cs.indiana.edu (Steve Hayman) Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Proposed monthly Frequently Axed Questions posting, round II Message-ID: <21764@iuvax.cs.indiana.edu> Date: 7 Jun 89 22:16:57 GMT Followup-To: comp.unix.questions Organization: Computer Science Department, Indiana University Lines: 564 Thanks again to everyone who made suggestions about this document. I appreciate your input, both positive and negative, and will continue to welcome suggestions or corrections. I wish I could have incorporated every suggestion, but somewhere you have to draw the line between not enough and too much detail. Just to make it clear, my main concern in posting this article is to help people out, to get them answers without their having to post articles. I don't want anybody flaming anybody for not having read this document, and I don't want some sort of rule (real or implied) that you have to read this before posting a question. With any luck, people will scan this at least once and then later when they have a question, even if they don't remember the answer, they'll think "Wasn't there something about this in 'Frequently Asked Questions'?" and go and check it out. I plan to start posting this on July 1 and every first of the month thereafter. For now I would like to leave it as a single article rather than splitting the Q/A and guidelines. Would posting a separate "diff" when things change be useful? Here's summary of the major differences between this posting and the one of a week ago: - added some new frequently asked questions and answers How do I rename "*.foo" to "*.bar"? Why do I get [some strange error message] when I "rsh host command" ? What does {awk,grep,fgrep,egrep,biff,cat} stand for? (Note - should anything be added to that last list? The meaning of "UNIX" is covered in the news.announce.newusers article and there's probably too much overlap between this and that already) - modified the suggestion that "most sites have at least a few Unix experts"; "many" is probably more accurate. (I got an interesting note from a fellow whose business is selling turnkey Xenix systems to churches and he says he really had to laugh at the remark about most sites having an expert.) - suggested that specific C questions should go to comp.lang.c - suggested need for an accurate "Subject: " line, e.g. not "Subject: Help" - deleted some well-intentioned suggestions in some of the answers in the interests of keeping this to a manageable size. (For instance I cut down on the amount of stuff about "find" in the section on deleting oddly-named files, and although the suggestion to make sure your shell scripts can handle files named "?" or "embedded blank" is a good one, it is only one of several things you need to do in a good shell script, and that would really be a good subject for another article.) - Various changes to the frequently questioned answers. Anyways, here's the latest version. Comments still welcome, this is probably the last revision I'll post before I start doing the real thing. Thanks for your support, and see you at Usenix. ..Steve === cut here === Subject: Welcome to comp.unix.questions and comp.unix.wizards [Monthly posting] Newsgroups: comp.unix.questions,comp.unix.wizards Followup-To: comp.unix.questions Comp.unix.questions and comp.unix.wizards are two of the most popular and highest volume newsgroups on Usenet. This article is a monthly attempt to remind potential posters about what is appropriate for each of the two newsgroups. If you would like to make any suggestions about the content of this article, please contact its maintainer at sahayman@iuvax.cs.indiana.edu or iuvax!sahayman . Later on in this article, you'll see the answers to some Frequently Asked Questions. Please don't ask these questions again, they've been answered plenty of times already. Thank you. This article includes answers to: How do I remove a file whose name begins with a "-" ? How do I remove a file with funny characters in the filename ? How do I get a recursive directory listing? How do I get the current directory into my prompt? How do I read characters from a terminal without requiring the user to hit RETURN? How do I read characters from the terminal in a shell script? How do I check to see if there are characters to be read without actually reading? How do I find the name of an open file? How do I rename "*.foo" to "*.bar"? Why do I get [some strange error message] when I "rsh host command" ? What does {awk,grep,fgrep,egrep,biff,cat} stand for? Also, if you have not already read the overall Usenet introductory material posted to "news.announce.newusers", please do. Much of this article overlaps with the common sense guidelines posted there. Should I Post My Unix Question to the Net? Often the answer is "No, you can get an answer a lot faster without posting a question." Before you post, you should try - o Reading the manual for your system. Some day you may encounter the phrase "RTFM", which stands for "Read the Fine Manual", (except 'F' doesn't really stand for "Fine"). If you ask someone a question and they tell you to RTFM, it's an indication that you haven't done your homework. For instance, if you are having trouble removing a file whose name begins with a "-", check the man page for "rm". It might tell you what you need to know. When people use terminology like "read(2)", they are referring to the "read" man page in section 2 of the manual (which you would see by using "man 2 read"). o Finding a knowledgeable user at your site. Many sites have at least a few Unix experts who will be happy to help you figure out how to remove a file whose name begins with "-". Many larger sites, particularly universities, may even have paid consultants whose job is to help you with Unix problems. Check with them first. o Find a good introductory book on Unix. There are plenty of such books available, and you will save yourself a lot of trouble by having one handy and consulting it frequently. Please remember that comp.unix.questions and comp.unix.wizards are read by over 50,000 people around the world, and that posting a question to either of these groups will cost a lot of time and money by the time your article is distributed to Japan, Australia, Norway, Israel, and all corners of North America. Should I Post to "comp.unix.questions" or "comp.unix.wizards" ? Comp.unix.wizards is intended for advanced discussion of Unix features - the sort of topics the average user never thinks about. Simple questions about using normal commands should never go there. Unfortunately, it's often hard to tell whether your question is simple until you know what the answer is. A good rule of thumb is - Don't post to comp.unix.wizards unless *you* *yourself* are a Unix wizard. Don't post to comp.unix.wizards just because you want to get the attention of a unix wizard. Many unix wizards read comp.unix.questions also and will be happy to help you out if they see your question there. Specific questions about the "C" language can go to comp.lang.c . What Information Should I Include? It's hard to include too much information. There are hundreds of different Unix systems out there, and they all have less in common than you might think. If you have a problem and are posting an article, please be sure to mention: o A descriptive subject line. Many people will decide whether to read your article solely on the basis of the subject line, so it should be a good statement of your problem. NOT GOOD GOOD "Help" "How do I sort a file by line length?" "Csh question" "csh core dumps when I use '$<'" o What computer you are using, and what specific version of the operating system it uses. For instance, SunOS 4.0.1, Sun 3/50 4.3BSD-tahoe, Vax 11/780 SVR3.2, 3b2 o If possible, the *exact* text of any error message you may have encountered. WRONG RIGHT "I can't print this file" "When I type 'lpr Filename', I get lpr: Filename: File too ugly to print What does this mean? It isn't in the man page. This is using Mueslix 9.3 on a Fax 68086502" It's a good idea to post unrelated questions in separate articles, so that people can keep different discussions separate. It's also a *very* good idea to include a line or two like this: "Please mail your answers to me and I'll summarize what I get and post the results to comp.unix.questions." This prevents many identical responses from different users to the same question from clogging up the newsgroup. And make sure you really summarize what you get - don't just concatenate all the mail you've received. It's also a good idea to read comp.unix.questions for at least a couple of weeks after you post your article to see what followup articles are posted. Should I Post an Answer to a Question? It's very tempting to post an answer to a question you read on the net, especially when you think "Aha, finally - a question I can answer!" Consider though that when a simple question is asked, such as the sort about to be answered below, many other people around the world already know the answer and may be posting their own reply. In order to avoid dozens of replies to simple questions, please wait a day or so and see if anyone else has already answered the question. If you have something special to contribute, please do so, but make sure you're not duplicating something someone else has already done. What About Posting Source Code? Posting small amounts of example code is fine (use comp.sources.unix to distribute complete programs) - but please make sure that your code runs (or at least compiles) properly. Don't just type it in while editing your posting and hope it will work, no matter how sure you are that it will. We all make mistakes. What About Those People Who Continue to Ask Stupid or Frequently Asked Questions In Spite of This Document? Just send them a polite mail message, possibly referring them to this document. There is no need to flame them on the net - it's busy enough as it is. FREQUENTLY ASKED QUESTIONS While these are all legitimate questions, they seem to crop up in comp.unix.questions on an annual basis, usually followed by plenty of replies (only some of which are correct) and then a period of griping about how the same questions keep coming up. You may also like to read the monthly article "Answers to Frequently Asked Questions" in the newsgroup "news.announce.newusers", which will tell you what "UNIX" stands for. With the variety of Unix systems in the world, it's hard to guarantee that these answers will work everywhere. Read your local manual pages before trying anything suggested here. If you have suggestions or corrections for any of these answers, please send them to to sahayman@iuvax.cs.indiana.edu or iuvax!sahayman. 1) How do I remove a file whose name begins with a "-" ? Figure out some way to name the file so that it doesn't begin with a dash. The simplest answer is to use rm ./-filename (assuming "-filename" is in the current directory, of course.) This method of avoiding the interpretation of the "-" works with other commands too. Many commands, particularly those that have been written to use the "getopt(3)" argument parsing routine, accept a "--" argument which means "this is the last option, anything after this is not an option", so your version of rm might handle "rm -- -filename". Some versions of rm that don't use getopt() treat a single "-" in the same way, so you can also try "rm - -filename". 2) How do I remove a file with funny characters in the filename ? The classic answers are rm -i some*pattern*that*matches*only*the*file*you*want which asks you whether you want to remove each file matching the indicated pattern; depending on your shell, this may not work if the filename has a character with the 8th bit set (the shell may strip that off); and rm -ri . which asks you whether to remove each file in the directory, answer "y" to the problem file and "n" to everything else., and which, unfortunately, doesn't work with many versions of rm; (always take a deep breath and think about what you're doing and double check what you typed when you use rm's "-r" flag) and find . -type f ... -ok rm '{}' \; where "..." is a group of predicates that uniquely identify the file. One possibility is to figure out the inode number of the problem file (use "ls -i .") and then use find . -inum 12345 -ok rm '{}' \; or find . -inum 12345 -ok mv '{}' new-file-name \; "-ok" is a safety check - it will prompt you for confirmation of the command it's about to execute. You can use "-exec" instead to avoid the prompting, if you want to live dangerously. If none of these work, find your system manager. 3) How do I get a recursive directory listing? One of the following may do what you want: ls -R (not all versions of "ls" have -R) find . -print (should work everywhere) If you're looking for a wildcard pattern that will match all ".c" files in this directory and below, you won't find one, but you can use % some-command `find . -name '*.c' -print` "find" is a powerful program. Learn about it. 4) How do I get the current directory into my prompt? It depends which shell you are using. It's easy with some shells, hard or impossible with others. C Shell (csh): Put this in your .cshrc - customize the prompt variable the way you want. alias cd 'chdir \!* && set prompt="${cwd}% "' If you use pushd and popd, you'll also need alias pushd 'pushd \!* && set prompt="${cwd%} "' alias popd 'popd \!* && set prompt="${cwd%} "' Some C shells don't keep a $cwd variable - you can use `pwd` instead. If you just want the last component of the current directory in your prompt ("mail% " instead of "/usr/spool/mail% ") you can do alias cd 'chdir \!* && set prompt="$cwd:t% "' Bourne Shell (sh): If you have a newer version of the Bourne Shell (SVR2 or newer) you can use a shell function to make your own command, "xcd" say: xcd { cd $* ; PS1="`pwd` $ "; } If you have an older Bourne shell, it's complicated but not impossible. Here's one way. Add this to your .profile file: LOGIN_SHELL=$$ export LOGIN_SHELL CMDFILE=/tmp/cd.$$ export CMDFILE PROMPTSIG=16 export PROMPTSIG trap '. $CMDFILE' $PROMPTSIG and then put this executable script (without the indentation!), let's call it "xcd", somewhere in your PATH : xcd directory - change directory and set prompt : by signalling the login shell to read a command file cat >${CMDFILE?"not set"} <