old-www/LDP/LG/issue23/lg_tips23.html

584 lines
21 KiB
HTML

<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>More 2 Cent Tips & Tricks Issue 23</title>
</head>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0020F0"
ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>&quot;Linux Gazette...<I>making Linux just a little more fun!</I>
&quot;</H4>
<P> <hr> <P>
<!-- QUICK TIPS SECTION ================================================== -->
<center>
<H1><A NAME="tips"><IMG ALIGN=MIDDLE ALT="" SRC="../gx/twocent.gif">
More 2&#162; Tips!</A></H1> <BR>
Send Linux Tips and Tricks to <A HREF="mailto:gazette@ssc.com">
gazette@ssc.com
</A></center>
<p><hr><p>
<H3>Contents:</H3>
<ul>
<li><a HREF="./lg_tips23.html#spin">Spinning Down Unused HDs</a>
<li><a HREF="./lg_tips23.html#find">Finding What You Want with find</a>
<li><a HREF="./lg_tips23.html#cutpaste">Cutting and Pasting Without a Mouse</a>
<li><a HREF="./lg_tips23.html#slow">Slow Modem</a>
<li><a HREF="./lg_tips23.html#string">Finding Strings with find</a>
<li><a HREF="./lg_tips23.html#calc">Another Calculator Tip</a>
<li><a HREF="./lg_tips23.html#laptop">Upgrading a Laptop Hard Disk</a>
<li><a HREF="./lg_tips23.html#wall">Wallpaper</a>
<li><a HREF="./lg_tips23.html#post">PostScript</a>
<li><a HREF="./lg_tips23.html#virtual">Linux Virtual Console Key Sequences</a>
<li><a HREF="./lg_tips23.html#hidden">Netscape Hidden "Easter Eggs"</a>
</ul>
<P> <hr> <P>
<!--================================================================-->
<a name="spin"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Spinning Down Unused HDs
</H3><P>
Date: Sat, 8 Nov 1997 18:34:07 +0100 (MET)<br>
From: Philipp Braunbeck <a
href="mailto:100.182763@germany.net">100.182763@germany.net</a><br>
<P>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.
<P>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.
<P>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!
<P>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.
<P>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?
<P> <hr> <P>
<!--================================================================-->
<a name="find"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Finding What You Want with find
</H3>
<P>
Date: Wed, 12 Nov 1997 16:14:43 +0000 (GMT)<br>
From: Jon Rabone <a href="mailto:jkr@camcon.co.uk">jkr@camcon.co.uk</a><br>
<P>In the October 97 issue, Dave Nelson suggests using
<pre>find . -type f -exec grep "string" /dev/null {} \;</pre>
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:
<pre>grep "string" `find . -type f`</pre>
<P>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.
<P> <hr> <P>
<!--================================================================-->
<a name="cutpaste"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Cutting and Pasting without a Mouse
</H3>
<P>
From: <a
href="mailto:fk5a005@rrz.uni-hamburg.de">fk5a005@rrz.uni-hamburg.de</a><br>
Date: Wed, 5 Nov 1997 18:58:41 +0100<br>
<P>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?
<ul>
<li>Use control-a and ESC to switch on Copy-mode.
<li>"Drive" thru your screen with j,k and all the other well known vi-movements.
<li>Mark the area to copy with the space-key.
<li>Mark the end of the area with a space-key.
<li>Go to another window with e.g. control-a n .
<li>Press control-] where you want the pasting to happen.
ready!
</ul>
<P>This was pasting without leaving your keyboard for a while!
<P>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.
<P>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!
<P>About emacs and completion:
<P>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.
<P>About atchange
<P>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:
<a
href="http://www-lmmb.ncifcrf.gov/~toms/atchange.html">http://www-lmmb.ncifcrf.gov/~toms/atchange.html</a>
<P>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 :)
<P> <hr> <P>
<!--================================================================-->
<a name="slow"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Slow Modem
</H3>
<P>
Date: Mon, 3 Nov 1997 17:45:13 -0600 (CST)<br>
From:Michael J. Hammel<a
href="mailto:mjhammel@long.emass.com">mjhammel@long.emass.com</a><br>
To: Larry E Scheib <a
href="mailto:scheib@tenet.edu">scheib@tenet.edu</a><br>
<P>In a previous message, Larry E Scheib says:
<P><I>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>
<P>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).
<P>Things that might affect this would be:
<ol>
<li>some other process sitting on cua0 - perhaps a getty?
<li>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.
</ol>
<P> <hr> <P>
<!--================================================================-->
<a name="string"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Finding Strings with find
</H3>
<P>
Date: Tue, 28 Oct 1997 16:31:47 +0100<br>
From: Gordon Walker <a
href="mailto:hellcat@easynet.fr">hellcat@easynet.fr</a><br>
<P>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
<pre>#!/bin/sh
## Recursively finds all strings in given or current directory
## Usage string_search &lt;dir&gt; &lt;string&gt; (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
</pre>
<P> <hr> <P>
<!--================================================================-->
<a name="calc"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Another Calculator Tip
</H3>
<P>
From: Frank Damgaard <a href="mailto:frank@diku.dk">frank@diku.dk</a><br>
Date: Thu, 23 Oct 1997 22:05:14 +0200 (METDST)
<P>In issue 21 there was a smart perl based command line calculator,
here is another one.
<P>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.
<P>Just place the following line in your ~/.tcshrc or type at the prompt:
<pre>alias calc 'awk "BEGIN{ print \!* }" '
# When calling calc do not escape "*":
# Example: calc (3+5)*4/5</pre>
<P> <hr> <P>
<!--================================================================-->
<a name="laptop"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Upgrading a Laptop Hard Disk
</H3>
<P>
Date: Fri, 24 Oct 1997 14:38:58 -0400<br>
From: Peter Teuben <a
href="mailto:teuben@astro.umd.edu">teuben@astro.umd.edu</a><br>
<P>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).
<P>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:
<ol>
<li>backup, using tar, the old /DOS partition accross the network
<li>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.
<li>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.
<li>by default RedHat mounts hda1 as 'dos', but you need to
re-mount this still empty partition as 'vfat':
<pre>umount /DOS
insmod vfat
mount -t vfat /dev/hda1 /DOS</pre>
<li>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.
<li>reboot the machine with a previously made 'emergency W95
bootfloppy' and run "SYS C:" to restore the bootimage
<li>reboot and select W95 from the LILO prompt, and it should all
work nicely now (it did for me).
</ol>
<P>Caveat: For FAT32 versions of W95 (from OSR2 or W98) you may need to
patch the 2.1.x kernels to include this.
<P> <hr> <P>
<!--================================================================-->
<a name="wall"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Wallpaper
</H3>
<P>
Date: Mon, 27 Oct 1997 14:38:35 +0100<br>
From: Roger Irwin <a href="mailto:irwin@mail.com">irwin@mail.com</a><br>
<P>Use netscape, got xv?
<P>Try running this script in your home directory:
<pre>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</pre>
<P>This will make you a custom wallpaper on the fly by fishing in netscapes
cache.
<P>I mapped this to my fvwm2 button bar by using the following lines in
.fvwm2rc95:
<pre>*FvwmButtons(Title Mood, Icon exit.xpm, \
Action 'Exec XVchange ')</pre>
<P>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....
<P> <hr> <P>
<!--================================================================-->
<a name="post"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
PostScript
</H3>
<P>
Date: Sun, 9 Nov 1997 22:00:31 +0000 (GMT)<br>
From: Ivan Griffin <a
href="mailto:ivan.griffin@ul.ie">ivan.griffin@ul.ie</a><br>
<P>Counting the Number of Pages in a file
<P>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:
<pre>grep -c '%%Page:' filename.ps</pre>
I generally tend to alias this to pspage in my .cshrc
<pre>alias pspage 'grep -c %%Page:'</pre>
<P>Printing 2up
<P>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:
<pre>alias psdouble 'pstops "2:0L@.7(21cm,0)+1L@.7(21cm,14.85cm)"'</pre>
<P>To use it, it is as simple as:
<pre>psdouble &lt; 1up.ps &gt; 2up.ps</pre>
<P>Microsoft Ugly PostScript
<P>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:
<P>/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?
<P>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).
<P> <hr> <P>
<!--================================================================-->
<a name="virtual"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Linux Virtual Console Key Sequences
</H3>
<P>
Date: Sun, 9 Nov 1997 22:00:31 +0000 (GMT)<br>
From: Ivan Griffin <a
href="mailto:ivan.griffin@ul.ie">ivan.griffin@ul.ie</a><br>
<P>Pressing these key sequences on a VC will dump information to the screen.
<P>Displaying task information:
<P>Ctrl-Scroll Lock gives:
<pre> 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
</pre>
<P>Displaying Memory Information
<P>Shift-Scroll Lock gives:
<pre>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</pre>
<P> <hr> <P>
<!--================================================================-->
<a name="hidden"></a>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
Netscape Hidden "Easter Eggs"
</H3>
<P>
Date: Sun, 9 Nov 1997 22:00:31 +0000 (GMT)<br>
From: Ivan Griffin <a
href="mailto:ivan.griffin@ul.ie">ivan.griffin@ul.ie</a><br>
<P>These special URLs do interesting things in Netscape Navigator and
Communicator.
<pre>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</pre>
<P>Ctrl-Alt-F take you to an interesting site :-)
<P> <hr> <P>
<!--================================================================-->
<center>Published in Linux Gazette Issue 23, December 1997</center>
<P> <hr> <P>
<!--================================================================-->
<A HREF="./index.html"><IMG SRC="../gx/indexnew.gif" ALT="[ TABLE OF
CONTENTS ]"></A> <A HREF="../index.html"><IMG SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A> <A HREF="./lg_mail23.html"><IMG SRC="../gx/back2.gif" ALT=" Back "></A>
<A HREF="./lg_bytes23.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
<h5>This page maintained by the Editor of <I>Linux Gazette</I>,
<A HREF="mailto: gazette@ssc.com">gazette@ssc.com</A><BR>
Copyright &copy; 1997 Specialized Systems Consultants, Inc. </H5>
<P>
<!--startcut ==========================================================-->
</body>
</html>
<!--endcut ============================================================-->