Welcome to Linux Support and Sun Help
Search LinuxSupport
From: Subject: Linux Quick Hacks Date: Tue, 17 Jul 2001 12:40:36 +0100 MIME-Version: 1.0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Location: http://www.troubleshooters.com/linux/quickhacks.htm X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Linux Quick Hacks

Troubleshoote= rs.Com=20 and T.C Linux = Library Present

Linux Quick = Hacks=20

Copyright (C) 2000-2001 by Steve Litt, All rights reserved. Material = provided=20 as-is, use at your own risk. =20


Ascii Character Lister

To list printable = characters=20 and their ascii values, do the following:
perl -e 'foreach $x =
(32..126){print "_" . chr($x) . "  " . $x . "\n"}' | grep =
To=20 find the ascii code for a specific character (other than the space = character,=20 use $ in this example), do this:
perl -e 'foreach $x =
(32..126){print "_" . chr($x) . "  " . $x . "\n"}' | grep =
Normal=20 characters don't need and can't use the backslash, so to find the asci = value of=20 lower case 'd' you'd do this:
perl -e 'foreach $x (32..126){print =
"_" . chr($x) . "  " . $x . "\n"}' | grep '_d'

To find the character corresponding to an ascii value, do this = (example=20 uses 100 as the ascii value):

perl -e 'foreach $x (32..126){print =
"_" . chr($x) . "  " . $x . "\n"}' | grep ' 100'

Man pages formatted as = text

Man=20 pages look great on console screens, but piped to files or to browsers = they=20 quickly degenerate into cluttered conglomerations of reverse linefeeds = and=20 backspaces designed to simulate "bold" on your console screen. You get = rid of=20 the clutter by piping the output of man through the = col=20 command. With no args, col blows off the reverse linefeeds but = leaves=20 the backspaces (^H). The command you want (using the ls man page as an = example)=20 is:
man ls | col -bx > myfile.txt
The preceding command = writes the man=20 page to myfile.txt, without backspaces (the -b) and with spaces = substituted for=20 tabs (-x).=20

Man pages formatted as = html

Here's a=20 CGI script that uses a command similar to that discussed in the = preceding=20 section to output a man page to a browser. I call it mann.cgi: =
#!/usr/bin/perl -w


use strict;


sub GetData()
  if($line =~ m/Tman=(.*)&Bsub/)
    $cmd = $1;
  elsif($line =~ m/Tman=(.*)$/)
    $cmd = $1;
    $cmd = "InternalError";

sub MakePageTop()
  print "Content-type: text/html\n\n";
  print "<html><head><title>Man Page =

  print =
  print "Man Page Displayer<p>\n";
  print =

sub MakeForm()
  print "<FORM ACTION=\"./mann.cgi\" METHOD=\"POST\">\n";
  print "<b>Command to look up:\n";
  print "<input type=\"text\" name=\"Tman\" size=\"24\"";
  print " value=\"$cmd\"></b>\n";
  print "<INPUT type=\"submit\" name=\"Bsub\" =
  print "</form>"; 

sub MakeManPage()
  print "<pre><b>";
  print `man $cmd -a | col -bx`;
  print "\n</b></pre>";

sub MakePageBottom()
  print "</body></html>\n"; 

sub main()


Shellscript File Tests

Here's = a script=20 to test for a file's existence:
if [ -e $file ]; then
 ./myUtil $file
[ -b $file ] True if file exists and is block special.
[ -c $file ] True if file exists and is character special.
[ -d $file ] True if file exists and is a directory.
[ -e $file ] True if file exists.
[ -f $file ] True if file exists and is a regular file.
[ -g $file ] True if file exists and is set-group-id.
[ -k $file ] True if file has its ``sticky'' bit set.
[ -L $file ] True if file exists and is a symbolic link.
[ -p $file ] True if file exists and is a named pipe.
[ -r $file ] True if file exists and is readable.
[ -s $file ] True if file exists and has a size greater than = zero.
[ -S $file ] True if file exists and is a socket.
[ -t $fd  ] True if fd is opened on a terminal.
[ -u $file ] True if file exists and its set-user-id bit is = set.
[ -w $file ] True if file exists and is writable.
[ -x $file ] True if file exists and is executable.
[ -O $file ] True if file exists and is owned by the effective user=20 id.
[ -G $file ] True if file exists and is owned by the effective group=20 id.

Directory Size Lister/Sorter

Have you ever = wondered=20 which directories and trees take up all the diskspace? Questions like = this come=20 during pruning/archiving, backup, and numerous other activities. Make = the=20 following oneliner script (I call it dirsizes) to find out: =
du -sm $(find $1 -type d -maxdepth 1 -xdev) | sort =

The preceding shellscript prints every directory below the one called = as an=20 argument, together with its size, sorted with the largest at the bottom. = We sort=20 largest at bottom so there's no necessity to pipe it to less. = Instead,=20 you can see the largest 24 on the screen after the command.=20

If you find a large tree, but can't delete the whole thing, you can = explore=20 just that tree by using its directory as the argument, and you'll see = all its=20 subtrees and how much space they take.=20

But let's say you want to see ALL directories in the tree, instantly = zeroing=20 in on big diskspace directories. Make the following shellscript, which I = call=20 alldirsizes:

find $1 -type d  | xargs du -sm | sort =

Both these scripts do more than just add filesizes. They take into = account=20 inodes, so they reveal the space that would be recovered if the = directories were=20 deleted.=20

Both of these scripts are most accurate when run as root, but they're = pretty=20 informative run as just a normal user.=20


X-Sender: =
X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.6 (32)
Date: Fri, 24 Nov 2000 11:59:15 -0500
To: leaplist@lists.leap-cf.org
From: Steve Litt <slitt@troubleshooters.com>
Subject: [LeapList] Cups tips
Reply-To: leaplist@lists.leap-cf.org
Sender: leaplist-admin@lists.leap-cf.org
X-Mailman-Version: 1.0rc2
List-Id: General Linux Discussion List for LEAP =
X-BeenThere: leaplist@lists.leap-cf.org

On my mandrake 72 I noticed that using lpr to print a text file was
printing too close to the left and cutting off half the first character.
This is a cups system.

So I looked at http://localhost:631, which is the cups equivalent of =
It pointed me to a cups manual, which noted that the lpr command can be
used to change margins:

lpr -o page-left=24 /etc/smb.conf

The preceding prints smb.conf with a left margin of 1/3 inch (24/72). =
are a smorgasbord of options for duplexing, characters per inch, page
ranges (and isn't that nice when a .ps or .pcl file jams in the middle),
and tons of other stuff. However, I couldn't make the brightness setting
work right, as when I made the text darker, the background on the last =
turned dark.

By the way, I'm sure there's some place where I can make the page-left
default 24 points, but I just haven't found it yet.


Mouse: Fast and Accurate Mousing Under = Linux

By=20 default, the mouse under Linux is typically much too slow, requiring = large hand=20 movements to move the pointer. This is inconvenient, and although I'm a = layman=20 with regard to ergonomics, I personally fear those large hand movements = put me=20 at greater risk for repetative motion injuries. Luckily, this problem is = easy to=20 fix.=20

Many people think the fix is to boost the acceleration. That makes = the mouse=20 fast enough, but requires you to move the mouse quickly to traverse = large=20 distances, then slowly to zero in on the exact target. With an overly = large=20 (like 5) acceleration, mousing resembles golf -- one or two drives = followed by a=20 couple of putts. Not good for productivity.=20

The problem isn't accelleration. The problem is that the pointer = moves too=20 few pixels per inch of mouse travel. You should be able to move a good = 600=20 pixels per inch of mouse travel, not the ~200 provided by a default = Linux box.=20 The solution is to add a resolution option to the pointer = section of=20 /etc/XFConfig86-4 file, as shown below:

# **************************************************
# Pointer section
# **************************************************
Section "InputDevice"

    Identifier "Mouse1"
    Driver      "mouse"
    Option "Protocol"    "imps/2"
    Option "ZAxisMapping" "4 5"
    Option "Device"      =
    Option "Emulate3Timeout"    "50"
    Option "Resolution" "1600"

# ChordMiddle is an option for some 3-button Logitech mice

#    Option "ChordMiddle"


You'll notice I use 1600 for the resolution. That's above the = maximum, so it=20 produces the maximum resolution. The preceding is for my Logitech = optical mouse,=20 but the Option "Resolution" "1600" line is appropriate for = pretty much=20 any mouse, although it's conceivable that for some mice you might want = to go=20 higher or lower than 1600.=20

After making the preceding addition, you must restart X to see the = result.=20

Once you've upped the resolution, you can tweak the accelleration. = Once I've=20 fixed the resolution, I like an acceleration value of 2. Here's the = command to=20 get it:

xset m 2 1
To get a 3 to 1 acceleration, use this: =
xset m 3 1
To make your mousing experience even better, use a = teflon=20 covered mouse pad. It's well worth the extra money.=20

Although technically trivial, the human-mouse interaction plays a = major role=20 in the perceived quality of the computer experience. Don't shortchange = yourself.=20 Tweak your mouse to your liking.

Smoothwall Tips

The default = Smoothwall intall=20 is kewl, but I've found a couple hacks to make it better for my setup. = First, as=20 shipped, Smoothwall defaults to the British English keyboard. If you = have an=20 American keyboard like I do, you need to change it or various keys like=20 backslash will input the wrong character. Go into file =20 /etc/rc.d/rc.sysinit and change the following line: =
/usr/bin/loadkeys =
To this:=20
/usr/bin/loadkeys =
I=20 changed uk to us, thereby enabling configuring for my keyboard.=20

Second, I use Lynx to dial and disconnect Smoothwall. Konqueror = doesn't work=20 with Smoothwall as of this writing, and Netscape is much too bloated. = But=20 Smoothwall 0.9.8 places 13 links, known as "the menu", before the dial = button,=20 meaning to get to the dial button in Lynx I need to press Tab 14 times. = I=20 removed the 13 links with the following change:=20

Change the following line of /home/httpd/cgi-bin/index.cgi: =

&openpage($tr{'main page'}, 1, $refresh);
To the = following:
&openpage($tr{'main page'}, 0, $refresh);
The = second argument of=20 openpage() defines whether or not to show the "menu", which is = the 13=20 links appearing at the top. Because these same links are reproduced = below the=20 dial, disconnect and refresh buttons of the main page, they can safely = be=20 removed on the main page. Of course, they must be preserved on other = pages, as=20 they're the main form of navigation from those pages.

Recording, Playing and Converting = sounds

First, make=20 sure aumix is installed, and use it to set both the record and play = volumes, and=20 make sure the microphone is the record device and not muted. Don't use a = GUI=20 mixer -- they sometimes get it wrong.=20

To record a song from the microphone, just do this:

$ rec =
If you want to change the volume, use -v, which is a=20 float where >1.0 amplifies, and <1.0 attenuates. Note our hearing = is=20 logrithmic.
$ rec -v2 mysong.au
To play it back, do this: =
$ play mysong.au
To convert it to a .wav, do this:
$ sox =
mysong.au mysong.wav
Sox can also amplify, flanger, phaser,=20 echo, and various other effects. See man sox.=20

Back = to=20 Troubleshooters.Com * Back to Linux=20 Library

Valid HTML 4.01! Valid CSS!