"Linux Gazette...making Linux just a little more fun! "


More 2¢ Tips!


Send Linux Tips and Tricks to gazette@linuxgazette.net


Contents:


Spinning Down Unused HDs

Date: Sat, 8 Nov 1997 18:34:07 +0100 (MET)
From: Philipp Braunbeck 100.182763@germany.net

I guess there's no more need to emphasize how much we all like LG. Here's just my humble-newbie-one-and-a-half.

If You're like me and You've been upgrading for a couple of years now You're likely to have several HD's on Your IDE- or SCSI-Interfaces. Now there's probably some GNU-Linux-partition and one or more other partitions with M$-stuff on a separate disk. I've got a 120MB Conner (with actually nothing on it, I use it as a backup-device; it used to be win3.1, but I don't need it anymore :-) which is horribly loud. In the old days of DOS one friend of mine wrote a little Pascal-program which would stop the disk after a period of time, and it would only restart on some (hardware?)-interrupt. Some modern BIOSes can do that job for You, but people told me, that either it doesn't work on Linux (because the BIOS is only used on bootup in order to get some basic configuration) or it is not recommended to do so anyway.

When I was on some adventure-trip through /usr/sbin, I discovered some new species called "hdparm", which should be included on any major distribution. The manual page says that you can use it to spin down any drive on Your system! All You need to do now is putting a line like "hdparm -S1 /dev/hdb" in some boot-startup-script (I guess the filenames differ in different distributions) and You're done. What a silence!

However, You shouldn't do it with Your working /-partition, as it syncs the disk every now and then and the disk will keep starting and stopping, and this is definitely not good for any HD.

If You like my 2-cent just go ahead and publish it. If not, there will certainly be a good reason for this. As I am a newbie, i.e. I've been using GNU/Linux for about one year now, I'm humble enough to admit that this hint seems more than obvious to any experienced user. But if You decide to publish it, I'd prefer that I can stay anonymous, not because I got anything to hide, but because I don't want to pretend to be someone I'm not, like a sysadmin or I dunno. I've got too much respect for them guys who are lots more intelligent than I am, but would they ever consider to mail something as primitive as I suggest to LG? It really is a matter of getting started for unexperienced users, finding that GNU/Linux gets even more powerful while sorting it all out. So just put it in "Clueless at the prompt" or where You like. Sign with Your name, You knew the trick anyway, didn't You?


Finding What You Want with find

Date: Wed, 12 Nov 1997 16:14:43 +0000 (GMT)
From: Jon Rabone jkr@camcon.co.uk

In the October 97 issue, Dave Nelson suggests using

find . -type f -exec grep "string" /dev/null {} \;
to persuade grep to print the filenames that it finds the search expression in. This starts up a grep for each file, however. A shorter and more efficient way of doing it uses backticks:
grep "string" `find . -type f`

Note however, that if the find matches a large number of files you may exceed a command line buffer in the shell and cause it to complain.


Cutting and Pasting without a Mouse

From: fk5a005@rrz.uni-hamburg.de
Date: Wed, 5 Nov 1997 18:58:41 +0100

It is possible, I did think there was no way but there is a way to cut and paste without any mouse. Just use screen-3.6x to achieve what you may have wanted for a long time. you use screen already but did you know how to use this cut-and-paste tool?

This was pasting without leaving your keyboard for a while!

Control-a can be any key to achieve a screen-3.6 command. There are many more very useful features with screen but i guess that like me there are people out there who may not know this very useful feature. Another hint: It is really worth printing the Manual. If like me you are going by train you can read the Manual x. I found out there are so many important features in so many programs I did not know and that did help me a lot after discovering.

About vim and completion: there is a feature that lets you complete words which you did write before which is very, very useful. press control-n in Insert-mode and vim will complete your word if you typed it before. It is even better: You can get vim to complete words that are in a different file. Just tell vim what the name of the file is with :set dictionary=file Then complete the word with control-x-control-k. Now imagine how much easier it may be to get a list of words with a grep command than to write down all kinds of abbreviations and put them into a file. This is a Killer-feature IMO!

About emacs and completion:

Emacs was first with completion or at least this kind of completion mentioned for vim goes back to 1992. What you need is hippie-exp.el which can perform all kinds of completion.

About atchange

There is a very nice script out there written in perl. I like it very much because it lets you perform an action whenever you change the date of a file. The action can be almost anything like calling another program and executing things or whatever you want. The idea came from Tom Schneider who has a page about atchange out there: https://www-lmmb.ncifcrf.gov/~toms/atchange.html

I strongly encourage you to read it, this is an idea, that can really save your time. The perl-script itself is only 68 lines of code. almost one half is explanation, the most important thing is the idea itself but Tom has a good page. So I don't tell you more right now :)


Slow Modem

Date: Mon, 3 Nov 1997 17:45:13 -0600 (CST)
From:Michael J. Hammelmjhammel@long.emass.com
To: Larry E Scheib scheib@tenet.edu

In a previous message, Larry E Scheib says:

When I access a remote site with Linux my screens paint painfully slowly; a problem I don't experience with Windows95. When my modem connects under Linux it replys "Connected at 38,400", the actual speed of my modem. The modem runs off of cua1, IRQ 3.

I'm not very good at debugging modem connections. I've never really had any problems with my dial-ups except when the network itself is bogged down. To be honest, I have no idea how fast my modem connections are actually running. I just know they're tolerable (they actually seem to run quite fast - I have a 33.6 modem).

Things that might affect this would be:

  1. some other process sitting on cua0 - perhaps a getty?
  2. You didn't run setserial, a command to setup your serial ports for use with modems. I've never run this myself, but I know others have had to do so in order to get better throughput. Perhaps its because I don't use MS so my ports are not switched back and forth between MS and Linux settings.


Finding Strings with find

Date: Tue, 28 Oct 1997 16:31:47 +0100
From: Gordon Walker hellcat@easynet.fr

Being new to Linux I find the Tips section very useful in general and the tip about searching for a string with find inspired me to write my first conditional Bash script. It finds a string in the current or given directory

#!/bin/sh
## Recursively finds all strings in given or current directory
## Usage string_search <dir> <string> (dir is optional)
## For example:		 "string_search fish " finds string "fish" in current
directory
##	and 		"string_search /water fish " finds string "fish" in directory
/water
if [ "$2" = "" ]; then
	find . -type f -exec grep "$1" /dev/null {} \;
else
	find $1 -type f -exec grep "$2" /dev/null {} \;
fi


Another Calculator Tip

From: Frank Damgaard frank@diku.dk
Date: Thu, 23 Oct 1997 22:05:14 +0200 (METDST)

In issue 21 there was a smart perl based command line calculator, here is another one.

I have for some years used a simple alias for the calculator command. The alias only requires awk, and that tcsh (or csh) is the running shell. This alias will not work with bash/sh/ksh since these shells do not allow arguments in aliases.

Just place the following line in your ~/.tcshrc or type at the prompt:

alias calc 'awk "BEGIN{ print \!* }" '
# When calling calc do not escape "*":
# Example:  calc (3+5)*4/5


Upgrading a Laptop Hard Disk

Date: Fri, 24 Oct 1997 14:38:58 -0400
From: Peter Teuben teuben@astro.umd.edu

I wanted to upgrade the harddisk of my laptop, which had gotten a bit tight with 800Mb and maintaining both linux and W95 (don't ask).

I got a new 2Gb drive, and of course wanted to install W95 as well as linux. I decided, despite my die-hard Slackware, to try RedHat4.2 for linux and basically "copying" W95. Since the laptop is on a local ethernet at home, I could make a backup of W95 on the desktop, and after linux was braught up, restore W95 back over the network. Indeed this worked quite nice, but you have to remember a few tricks. Here were my basic steps:

  1. backup, using tar, the old /DOS partition accross the network
  2. replace drive, partitioned as dos on /dev/hda1, swap on hda2, ext2 on hda3 and hda4. Don't forget to toggle the bootable flags of hda1.
  3. installed linux on hda3, and did 'mkdosfs /dev/hda1' to format the dos partition from within linux (using DOS bootfloppy and FORMAT should work just as well, see my FAT32 caveat below) LILO was installed at this stage to boot linux as well as W95.
  4. by default RedHat mounts hda1 as 'dos', but you need to re-mount this still empty partition as 'vfat':
    umount /DOS
    		insmod vfat
            mount -t vfat /dev/hda1 /DOS
  5. untar the previously saved dos.tar back to /DOS, via the network from the desktop machine. Since /DOS is vfat, it will properly keep the long names.
  6. reboot the machine with a previously made 'emergency W95 bootfloppy' and run "SYS C:" to restore the bootimage
  7. reboot and select W95 from the LILO prompt, and it should all work nicely now (it did for me).

Caveat: For FAT32 versions of W95 (from OSR2 or W98) you may need to patch the 2.1.x kernels to include this.


Wallpaper

Date: Mon, 27 Oct 1997 14:38:35 +0100
From: Roger Irwin irwin@mail.com

Use netscape, got xv?

Try running this script in your home directory:

rm -f XVbaa
for foo in .netscape/cache/*
do
for baa in $foo/*.gif
do
echo $baa >>XVbaa
done
done
xv -root -quit -random -flist XVbaa

This will make you a custom wallpaper on the fly by fishing in netscapes cache.

I mapped this to my fvwm2 button bar by using the following lines in .fvwm2rc95:

*FvwmButtons(Title Mood, Icon exit.xpm, \
       Action 'Exec XVchange ')

This goes in the FVWM buttons section in the middle of the other lines that define the other buttons.... When I hit the Mood button, the wallpaper changes. I suppose a lazier person might use crontab....


PostScript

Date: Sun, 9 Nov 1997 22:00:31 +0000 (GMT)
From: Ivan Griffin ivan.griffin@ul.ie

Counting the Number of Pages in a file

To count the number of pages in a PostScript file, you are relying on the creator of the file to have been a sociable application and to have followed the Adobe Document Structuring Conventions (ADSC). These conventions entail the automatic placement of comments (%%) in the PostScript source so that additional applications will find it easier (and indeed, possible!) to post-process the PostScript without having to interpret it. They are generally ignored by PostScript interpreters and printers. The comment '%%Page:' delimits each new page. So to count the number of pages in a DSC compliant PostScript file, all you have to do is grep for the number of '%%Page:' markers:

grep -c '%%Page:' filename.ps
I generally tend to alias this to pspage in my .cshrc
alias pspage 'grep -c %%Page:'

Printing 2up

The utility pstops, part of the psutils package, allows you to process a PostScript file to enable 2up printing. I find the following works for A4 (European) paper -- the measurements will need to be tweaked for US Letter:

alias psdouble 'pstops "2:0L@.7(21cm,0)+1L@.7(21cm,14.85cm)"'

To use it, it is as simple as:

psdouble < 1up.ps > 2up.ps

Microsoft Ugly PostScript

Quite often in PostScript generated by the Microsoft Windows driver, it requires the interpreter to have 30MB of memory, and refuses to print otherwise!! This is quite incredible, and I have found that it always seems to print perfectly well if this artifical limit is removed. The PostScript in question is:

/VM? {vmstatus exch sub exch pop gt { [ (This job requires more memory than is available in this printer.) 100 500 (Try one or more of the following, and then print again:) 100 485 (In the PostScript dialog box, click Optimize For Portability.) 115 470 (In the Device Options dialog box, make sure the Available Printer Memory is accurate.) 115 455 (Reduce the number of fonts in the document.) 115 440 (Print the document in parts.) 115 425 12 /Times-Roman showpage (%%[ PrinterError: Low Printer VM ]%%) = true FatalErrorIf}if} bind def 30000 VM?

The line "30000 VM?" checks that (roughly) 30MB of memory is available in the printer. Deleting this line is sufficient to ensure that the check is not performed, and that the job will now print (or be interpreted successfully in ghostview for example).


Linux Virtual Console Key Sequences

Date: Sun, 9 Nov 1997 22:00:31 +0000 (GMT)
From: Ivan Griffin ivan.griffin@ul.ie

Pressing these key sequences on a VC will dump information to the screen.

Displaying task information:

Ctrl-Scroll Lock gives:

             free            sibling
 task       PC  stack  pid father child younger older
swapper  0 R current  4096   0   0   1
init    1 S FFFFFFFF 2676   1   0  706
kflushd  2 S 00000000 3984   2   1       3
kswapd   3 S 00000000 3976   3   1       4   2
nfsiod   4 S 00000000 3520   4   1       5   3
nfsiod   5 S 00000000 3520   5   1       6   4
nfsiod   6 S 00000000 3520   6   1       7   5
nfsiod   7 S 00000000 3520   7   1      21   6
bash    8 S 00000000 3012  172  164  711
login   9 S 00000000 2820  164   1  172   166  135
kerneld  10 S 00000000 3224  21   1      76   7
login   11 S 00000000 3012  706   1  712      571
syslogd  12 S FFFFFFFF 3192  76   1      85  21
klogd   13 R 00000000 3404  85   1      96  76
crond   14 S 00000000 3480  96   1      108  85
inetd   15 S FFFFFFFF 3464  108   1      119  96
lpd    16 S FFFFFFFF 3376  119   1      135  108
gpm    17 S 000B206C 3368  135   1      164  119
vi    18 S FFFFFFFF 3012  711  172
mingetty 19 S FFFFFFFF 3012  166   1      167  164
bash   20 S 00000000 3012  712  706  724
httpd   21 S 00000000 3460  573  571      574
httpd   22 S 00000000 3600  574  571      575  573
httpd   23 S 00000000 3308  571   1  579   706  171
httpd   24 S 00000000 3600  575  571      576  574
mingetty 25 S FFFFFFFF 3012  167   1      168  166
mingetty 26 S FFFFFFFF 3012  168   1      169  167
mingetty 27 S FFFFFFFF 3012  169   1      171  168
httpd   28 S 00000000 3600  576  571      577  575
update  29 S 00000000 3460  171   1      571  169
httpd   30 S 00000000 3600  577  571      579  576
vi    31 S FFFFFFFF 3012  724  712
httpd   32 S 00000000 3600  579  571         577

Displaying Memory Information

Shift-Scroll Lock gives:

Mem-info:
Free pages:    3136kB
 ( 4*4kB 0*8kB 1*16kB 1*32kB 0*64kB 24*128kB = 3136kB)
Swap cache: add 0/0, delete 231912/0, find 0/0
Free swap:    16596kB
5120 pages of RAM
789 free pages
449 reserved pages
2572 pages shared
Buffer memory:   2324kB
Buffer heads:   2340
Buffer blocks:   2324
Buffer[0] mem: 1953 buffers, 10 used (last=1953), 0 locked, 0 protected, 0 dirty 0 shrd
Buffer[2] mem: 337 buffers, 25 used (last=337), 0 locked, 0 protected, 0 dirty 0 shrd
Buffer[4] mem: 3 buffers, 3 used (last=3), 0 locked, 0 protected, 3 dirty 0 shrdSize  [LAV]   Free Clean Unshar   Lck  Lck1  Dirty Shared
 512 [  0]:    0    0    0    0    0    0    0
 1024 [ 186]:   31  1953    0   337    0    3    0
 2048 [  0]:    0    0    0    0    0    0    0
 4096 [  0]:    0    0    0    0    0    0    0
 8192 [  0]:    0    0    0    0    0    0
0


Netscape Hidden "Easter Eggs"

Date: Sun, 9 Nov 1997 22:00:31 +0000 (GMT)
From: Ivan Griffin ivan.griffin@ul.ie

These special URLs do interesting things in Netscape Navigator and Communicator.

about:cache gives details on your cache
about:global gives details about global history
about:memory-cache
about:image-cache
about:document
about:hype
about:plugins
about:editfilenew

view-source:URL opens source window of the URL

Ctrl-Alt-F take you to an interesting site :-)


Published in Linux Gazette Issue 23, December 1997


[ TABLE OF 
CONTENTS ] [ FRONT PAGE ]  Back  Next


This page maintained by the Editor of Linux Gazette, gazette@linuxgazette.net
Copyright © 1997 Specialized Systems Consultants, Inc.