Xref: utzoo comp.unix.questions:13965 comp.unix.wizards:16531 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!sahayman From: sahayman@iuvax.cs.indiana.edu (Steve Hayman) Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Proposed monthly comp.unix.{questions,wizards} article Message-ID: <21440@iuvax.cs.indiana.edu> Date: 31 May 89 21:23:36 GMT Reply-To: sahayman@iuvax.cs.indiana.edu (Steve Hayman) Followup-To: comp.unix.questions Organization: Computer Science Department, Indiana University Lines: 367 Here is version 0.9 of an article I'd like to post every month to comp.unix.questions and comp.unix.wizards. I welcome any comments. Thanks to everyone who either mailed or posted suggestions, including David Elliott, John Cowan, Paul English, Don Libes (whose "Life with Unix" really is a great book), Mike Liveright, Jimmy Aitken, Giles Lean, Jim Kingdon, Steve Kinzler, Brad Templeton and perhaps some others who I have inadvertently overlooked. This wound up being longer than I thought it would be. Perhaps it should be split into two articles - "Guidelines" and "Frequently Asked Questions". Anyway, I welcome any and all comments, and especially corrections if there are any blatant goofs in here. Steve Hayman sahayman@iuvax.cs.indiana.edu 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 sahayman@iuvax.cs.indiana.edu. 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? Also, if you have not already read the overall Usenet introductory material posted to "news.announce.newusers", please do. Again, thank you. 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. Most 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 "-". 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. 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 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 UnAX 9.3 on a Vax 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 responsed 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. If you're posting a shell script for others to use, remember that file names can contain blanks and characters such as '?', so try to make sure you script can handle those properly. 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. Suggestions or corrections should be sent to sahayman@iuvax.cs.indiana.edu . 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 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) and rm -ir . (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) and find . -type f ... -exec 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 -exec rm '{}' \; or find . -inum 12345 -exec mv '{}' new-file-name \; If none of these work, find your system manager. 3) How do I get a recursive directory listing? There are a couple of ways. The "ls" command has a "-R" option that makes it recursively descend through directories, so you could use "ls -lR /some/directory". If you just need a list of files, you can use "find". find /some/directory -print or if you want to get fancy, there is a lot you can do with this powerful program: # Ordinary files only find /some/directory -type f -print # Directories only find /some/directory -type d -print # Everything beneath a couple of different directories find /some/directory /another/directory -print # "ls -l" all of my files that are bigger than 300 blocks # if your machine has "xargs", you can use find /my/home/directory -type f -size +300 -print | xargs ls -l # or later BSD versions of find will let you use find /my/home/directory -type f -size +300 -ls 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 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): 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"} <