Renaming batches of files

If you’re coming to BeOS from the DOS world, you expect Terminal to be a lot more powerful than DOS. And it is. But with power comes an occasional price — some things are more complex to accomplish in bash than in DOS. A good example of this is in renaming large batches of files. Let’s say you’ve got a directory containing 500 text files, all ending with the .txt extension, and you want to make them end in .html. In DOS, this would be as simple as typing ren *.txt *.html. Since the bash command for renaming files is mv, you might expect you can type mv *.txt *.html. But it doesn’t work that way.
It would take a complex explanation of exactly how the bash shell works to explain why not, but if you need to accomplish this task, here’s how: type the following into the shell, hitting Enter after each line.

for i in *.txt
do
mv "$i" "$(echo $i | sed s/.txt$/.html/)"
done

In a nutshell, here’s what’s going on: you establish a loop to go through all the filenames in the current directory ending in .txt (* refers to all files in the current directory). „Do“ means you’re going to look at the first file and do something with it. That something is the move command, mv. We move the first file from its current location of {variable} to {variable.html}. The tricky part is that we need to use sed (the stream editor) to substitute the string „txt“ at the end of the line with the string „html“. Done means we’re ready to move to the next file, and also serves as a flag for the process to exit when all files have been processed.
If you need to use this function frequently, save the whole block as a script prefaced with the magic cookie #!/bin/sh and call it „ren“ or something else intuitive.
Note that just changing the extensions will not change the filetypes, because BeOS doesn’t use extensions as its primary means of identifying filetypes. To do that, see the tip Batch-changing filetypes.

 

Splitting text files

If you’ve got a big text document you’d like split into many smaller files, you can accomplish this with the csplit shell tool. Unfortunately, if you don’t speak Unix-ese fluently, the meager documentation isn’t going to help figure out to use this effectively (or many of the bash tools, for that matter). For documentation in plain English, get yourself a good book such as Learning the Bash Shell, from O’Reilly. Meanwhile, here’s a brief on splitting files. csplit has many options, or flags for achieving precise control. You give these to csplit while entering your command, which in turn affects the format of the output. Let’s take an example. Say you’ve got a report with many chapters, all as a single doc, and now you want to split each chapte off into a separate file. Assume that each chapter begins with the text, „Chapter:“. And assume you want every resulting filename to start with „doc.“ The existing file is called Report. Here’s your command: csplit -f doc Report /Chapter:/ {*} The -f flag specifies the prefix, so that every file gets named doc1, doc2, etc. You could give more arguments here, such as -n 3 to specify that numbering takes place in a three-digit scheme. Then comes the input filename, then the string to be searched on, surrounded by /s . Finally, the {*} specifies that csplit should keep on doing its thing until it runs out of instances of the text string.

 

Customize behavior of the mailbox replicant

As you know, double-clicking the mailbox icon in the Deskbar launches the folder /boot/home/mail/in . But did you know that it’s not hard-linked to that destination? You can actually launch any program or file you like from this icon with a simple tweak.
Clicking the mailbox icon will cause BeOS to look in /boot/home/mail for a symlink called „mailbox.“ By default, that link just points to „in“ folder. If you’d rather launch, say Mail-It or Postmaster, create a symlink to one of those apps in /boot/home/mail and rename it to „mailbox.“ Go nuts.

 

Finding BeOS docs at be.com

There is a large collection of document resources posted in various places at the Be web site. As always, it’s a good idea to read the available documentation before asking questions in online forums — that’s what the docs are there for.
This page is a fairly complete list of URLs for those documents – as of April 18, 1998. You can download this page and use it as a ‚local‘ html page to jump to each url or use it online as the base for visiting any or all documents.
Tip for viewing these docs without losing this page: If you point to a url, press and hold down the first mouse button, and view the popup menu that lauches, select ‚open in new window‘ to get a second browser window filled with the url contents. When you are done reading or Saving that page, just close this second window and choose another url in this page. Some browsers have a preset limit of 4 windows – you can change this in your browser’s preferences feature (somewhere).
Each url for a page posted at Be (www.be.com) is followed by a brief description of the url’s contents. http://www.be.com/documentation/user_docs/ This is the BeOS user guide – an html equivalent to the user manual that ships with BeOS R3. Contains many important explanations of BeOS features and ways of using those features. If you don’t own BeOS R3 yet, you can get an excellent idea of what it is like just by reading this set of pages. http://www.be.com/documentation/be_book/ The Be Book – programmer’s guide to BeOS. This is the table of contents page with links to all chapters – and to a downloadable copy of the whole book. The Be Book is updated regularly. You need this. A printed version of this book and more advanced books on programming for BeOS are available at Amazon.com and are listed at Be’s web site with many other useful books on related topics. You can purchase via the amazon.com link at Be to receive discounts and support Be’s advertising of these books.
http://www.be.com/developers/dev_library.html master page of the developer documents, bug database, and many useful documents that will benefit end users as much as developers. Try looking over each item linked to and be sure to scroll down the page to find links to Be Book and BASH manual in html format.
http://www.be.com/documentation/shell_tools/ BASH shell docs in html and the ‚ve‘ command line editor manual in html are linked from this page. Archives in Macintosh and UNIX formats for both document sets are at the top of this page. If you have nothing else to do while waiting for Intel applications to arrive, consider learning about BASH, ve, and the world of UNIX command line work. There is a vast array of potential (and new learning experiences) awaiting you. And more than a few ‚gotchas‘.
http://www.be.com/aboutbe/benewsletter/article_index.html
The Be newsletter – far more than just news – AND in a new, improved format that is guaranteed to leave you breathless. All articles from past newsletters are now individually linked and categorized under suitable headings. Down the page are Jean-Louis Gassee’s articles – which are a must read for everyone. Yes, this man is a unique star in the firmament of computing, clear and concise writing, and other things. If you think that I have enormous respect for the CEO of Be, you are correct. Also linked to this page are archives of the newsletter collection – in several formats, one suitable for every platform (zip, Mac, and UNIX) – well, almost everyone.
The newsletter covers news about Be and Be events, sage comments by Jean-Louis, incredibly thorough programming dissertations by the experts at Be, and some delightful asides. It exemplifies a ‚people communicating with people‘ attitude. http://www.be.com/aboutbe/whatsbe.html Okay, this page has lots more than just links to documents, but it has lots of links to all kinds of documents – links that may not be found as easily on other pages. This is a popourri of links that is handy to look through. http://www.be.com/support/qandas/ This is the master table of contents for FAQs about BeOS on PPC and on Intel platforms. Links posted here will take you to information about hardware for each platform that BeOS runs on. Some of it anyway. Well, most of it. The Be web site is getting reorganized and this is THE place to look for many bits of information that are not officially considered documents. This particular page was updated by Be on April 16, 1998 – so it contains many links of value. If you only want to read about Be, Be partners, and similar corporate matters, just scroll down to the bottom of the page. There is even a link to developer discussions.
Now if you are looking for an answer to ‚why my AWE64 sound card doesn’t work‘ – well….. maybe later. Well, folks, that is about it for right now. Chances are excellent that you will find ANYTHING at the Be web site either from the home page or from one of the links listed above. Some of the pages have so many links that it is not worth listing them individually here. Try that last link for links to Intel specific and PPC specific hardware QANDAs – all of them. Some webmaster has been working HARD to accommodate visitors.

 

NetPositive: Monitoring traffic

You can launch NetPositive 2.0.2 or later from the Terminal with the –ezdebug flag to get a list of all URLs that NetPositive has opened:

NetPositive --ezdebug

Later on, you can save this list to a text file for a complete record of the sites you’ve visited during the current session.
NetPositive 3.0d1 adds the –dump switch:

NetPositive --dump

which will spit out a complete log of your transactions for every page you visit, including HTTP headers and all binary data for images. Hint: think scripting possibilities.

 

Sound check

An easy way to see if your soundcard is working (without relying on third-party apps) is to open the Media preferences panel, turn up the volume, then open a Terminal and press control-G.
If you now hear a beep coming from your external speakers, you have a working sound card. If the beep comes from the internal beeper/speaker, your soundcard is not working with BeOS. Of course, the latter case only means it is currently not working, not that you cannot get it to work by using a 3rd party driver or some such.


Be’s Jon Wätte adds:
To see whether your sound card is supposed to work under version R4 of BeOS, all you have to do is open up a Terminal, and type:

 ls -l /dev/audio/old 

If some name like „awe64“ or „cs4226“ or „sonic_vibes“ or „ymf714“ shows up, your sound card is recognized and should be making sound. If it’s not, you may not have a Beep or Startup sound configured in the Sounds preferences panel: open that panel and choose some sounds and you should be all set.
If you still cannot hear anything, open the Media preference panel, Audio section, and make sure to uncheck all „Mute“ checkboxes in „Output“ and „Mixer“ that may be active.
Of course, the best test is to read the hardware compatibility list found on the Be web site.


Bjoern Wilmsmann (wilmsmann@pwx-webhosting.de) adds:
If your supported soundcard is not working under BeOS, check for resource conflicts in the Devices preferences panel and set it to another IRQ, or put the card in P&P mode (either via jumpers or the BIOS).

 

Eject floppy disks (PowerPC)

You have a MacOS box. There’s no eject button on the floppy drive (not counting the last-resort paperclip trick).
You put in a floppy disk. It’s not BFS, HFS, or another BeOS-readable format. You can’t mount it. So how do you eject it?

Simple: Use the „eject“ command from the shell, and the disk pops right out.

 

Telnet to pine

Telnet’ing to PINE on a remote server does not work with Terminal, since the environment variable TERM is set to ‚beterm‘, and PINE does not recognize this kind of terminal.
This can be solved by typing export TERM=vt100 in the Terminal, or adding it to /boot/home/.profile. Depending on your Terminal needs, you can also use export TERM=ansi (or any other terminal type).
Note that this tip does not refer to the BeOS port of PINE, but rather using a remote copy of PINE from within Be’s Terminal.


Marton Fabo (morton@eik.bme.hu) adds:
Another solution applies to systems using termcap. You can simply put a .termcap file into your home directory on the remote machine, which includes the beterm-part of the Be-supplied termcap (you can find it in /boot/beos/etc). No more hacks — pine will be happy with
TERM==beterm.

 

Demystifying IDE modes and jumpers

IDE devices have 2 or 3 active modes and one ‚don’t care‘ mode. A controller channel in most computers supports up to 2 devices, one jumpered as active master and one jumpered as active slave. Just to confuse matters, most IDE devices carry a jumper or even two jumpers that may be doing nothing, just sitting in a ’single‘ or ‚don’t care‘ mode. This can be the situation with consumer computers built after 1996, where each of two IDE devices can just be plugged into each of the two IDE channels built into the motherboard. A special mode called Cable Select is provided on hard drives – but used only with special IDE cables in RAID systems.
When you are faced with changing IDE devices around to install and run BeOS, the best – and only – plan is to first contact the manufacturer of the computer system or the manufacturer of each device for correct jumper information. Historically, hard drive jumper positions have changed between models from the same firm AND between units of the same model. You should write down complete model and serial numbers to completely identify the device. These are usually on a label on the top of each unit, so removing the devices from their mounting slots is necessary.
Before you undertake this chore, turn on your system and look at the messages on the screen. The first group of messages will include one on using a function key to launch the Setup program built into your bios. Do this. Setup will show, on its first page, the current status of your IDE devices AND their logical locations on the IDE channel(s). You may not have to change anything.
As BeOS matures, its ability to handle IDE devices will undoubtedly become as flexible as the handling provided in Windows95, so moving jumpers around should become a nice tale to tell future generations.

 

Graphical bootup fortune

You’re probably already familiar with the bash fortune function. It’s also easy to make fortunes pop up in graphical alert boxes. Just type this into Terminal:

alert "`fortune`"

Like it? Add it to your UserBootScript and you’ll get a fortune window every time you boot your BeOS system.
For more on using the alert function, see the tip Alert Boxes.

 
 

Kategorien

 
 
Blogroll
Resources