Linux Tricks and Tips

I find that in using Linux, I stir up a few new ideas every once and a while. Also, occasionally, I find that a process I need to use has not been well documented. So this is a repository that may, I hope, help some others who are using Linux.
Last modified circa 2005
  • Ad free browsing!
  • Kill Netscape zombie processes
  • Unusual Zip disk formatting (create a Windows compatible disk)
  • Type1 fonts
  • Vi global replace
  • Getting True Type fonts to work under Linux
    Copy this text to a file called "kn" in /usr/local/bin and then use the command "chmod +x /usr/local/bin/kn" to make it executable.
    #!/usr/bin/perl
    $netscapeName = "nets";

    #####################
    # kn - kill Netscape
    #####################
    # Author: Andy Deck
    # http://artcontext.com
    # Developing Java under RedHat 6, Netscape 4.61
    # often freezes up, so I'm often killing
    # zombie Netscape processes. If you are
    # having the same problem, kn is easy
    # to type.

    # Possible improvement: -n flag option to
    # start a new Netscape process.

    # A few lines of perl...

    open(PS, "ps -ax | grep $netscapeName | grep -v grep |");
    while($line=){
    ($slot1,$slot2,$fluf) = split(/\ +/,$line);
    # this ps split is unpredictable
    # so we check for a number
    if($slot1 =~ /[0-9]/){
    `kill -9 $slot1`;
    print("Killing $slot1\n");
    }
    else{
    print("Killing $slot2\n");
    `kill -9 $slot2`;
    }
    }
    close(PS);

    Back to top


    There are a number of tutorial pages on the web that explain how to mount PC-formatted zip disks under Linux. But what if you have a Mac formatted disk, or a Linux formatted disk, and you need to make it into a PC zip disk? The following are steps I took to mount a zip disk under the Linux OS and format it as a VFAT, Windows-compatible disk that I could send to someone who doesn't use Linux.
  • First, I needed to download the package for mkdosfs which I either did not install originally, or wasn't part of the default Redhat 6.0 system. It turns out that package was named mkdosfs-ygg-0.3b-9cl.i386.rpm. You can find it with ftpsearch.lycos.com or something similar.
  • Installed the thing using "rpm -Uvh mkdosfs-ygg-0.3b-9cl.i386.rpm"
  • This added mkdosfs to my /sbin folder
  • Next, I put the zip disk in my SCSI Zip drive (not all Zip drives use SCSI)
  • Having booted and mounted this device before, I know that it is /dev/sdd
  • I used "fdisk   /dev/sdd" to enter a utility that alters the disk
  • I used option "n" to add a new partition
  • Given a list of drive types, I chose the option for "VFAT 32", then chose "p" for primary and "1" as the partition. The beginning block was 1 and the ending block was 1024
  • Next, I used option "w" to write the changes to disk, and "q" for quit
  • Next I actually used the mkdosfs program with "mkdosfs /dev/sdd1"
  • If you do not have a folder created for the mount point, you'll need to create it: "mkdir /mnt/zip"
  • Last, I mounted the disk with mount: "mount -t vfat /dev/sdd1 /mnt/zip"

    Alternatively, you can use mke2fs to create a standard Linux file system on the same disk: "mke2fs /dev/sdd1". In this case the mount command would be "mount -t ext2 /dev/sdd1 /mnt/zip"

  • Back to top


    If you are like me, you'd prefer to see fewer ads when you browse. Depending on whether the web site designers specify a specific width=# and height=# for the banner images, you may or may not see the familiar "broken image" icon. In either case, you won't be distracted all the time with advertising.
  • First you edit your /etc/resolv.conf file so that it specifies that the domain name resolution sequence is: local /etc/hosts file first, domain name server second. This is accomplished by adding the following line to your /etc/resolv.conf file:

      hostresorder local bind
  • Next, you need to find the names of some hosts that are delivering the ads you want to block. Fortunately, most so-called content providers who use advertising subcontract their ad-image delivery to companies like doubleclick, so the fact that an image is an ad can often be identified by the hostname that delivers it. The way to find out what host an image comes from is to use (under Netscape) the "View image" (right click on image) option. When you are viewing the image independent of its original HTML context, you will be able to read the name of the host it came from. Often it is one of a few large ad-delivery companies.
  • You will need to find some IP numbers to associate with the these ads.somecompany.com server names. By associating the wrong IP number with the name, and telling your domain name resolution system to work primarily from the local /etc/hosts file, you will be preventing the images from being found. You could use just about any IP address that will point to a functioning web server. But why just choose random IP numbers? Why not cross-map the IP addresses to other ad-delivery sites? So far, I don't think it's illegal to make HTTP requests for non-existent documents every once in a while.
                                                          
        DocNotFound <-- 4 ----------------------------------+----------+
                                                            | qAds.com |
    1 GET q.gif from qAds.com          3  GET  z.gif  img ->| web      |    
                \                    /                      | server   |
                  - >               /                       +----------+ 
                    2  /etc/hosts -+
                  - >               \                       +----------+ 
                /                    \                      | zAds.com |
    1 GET z.gif from zAds.com          3  GET  q.gif  img ->| web      |
                                                            | server   |
        DocNotFound <-- 4 ----------------------------------+----------+
    
  • If you don't know the IP address of your "favorite" ad deliverers, use:
      nslookup somehost.com
  • The IP number associated with the hostname must resolve to a real server, otherwise, the failure of the server to respond will likely slow down your browsing.
  • My /etc/hosts includes the following mappings:
    207.46.131.137 m.doubleclick.net
    207.46.131.30  ad.doubleclick.net
    207.46.130.149 ads05.focalink.com
    205.188.146.23 ads.tucows.com
    204.162.96.173 ads.lycos.com
    
    Back to top
    I've installed Type1 fonts (Postscript), which give better, smoother contours for letters in graphics programs like GIMP. Trouble is, the Type1 fonts don't seem to work well under Netscape, so I had to leave some of the 100dpi and 75dpi fonts around for Netscape to use (it seems to be able to scale these more effectively under my Redhat 6 OS).

    Under Redhat 6, there is a fontserver called xfs that is started at boot time. I've learned that the config file for this server is /etc/X11/fs/config. The fonts on my system are located at /usr/X11R6/lib/X11/fonts/ (sub-directories of this folder like Type1, 100dpi, 75dpi, etc.). In order to remove some of the fonts I didn't want or weren't really functional, I removed the font files, such as jiskan16.pcf.gz, and then typed the command to rebuild the folder's font database (fonts.dir, fonts.alias). That command is "mkfontdir" and must be typed inside of the affected directory. After removing and rebuilding the database, I restarted the xfs server using the init mechanism:

      /etc/rc.d/init.d/xfs restart
    Then I killed the X server and restarted it by exiting the window manager and restarting it (startx). At this point, I could launch GIMP and the font I was trying to get rid of was then no longer in the font list. This sytem is ridiculous, and I'm writing it down in part so I'll be able to remember how to do it when Redhat 7 comes along, assuming they don't make this a bit easier!

    Finally, in order to install the Type1 fonts, I located RPM files like xfreefonts-0.10-9.noarch.rpm, freefonts-0.10-9.noarch.rpm, and type1inst-0.6.1-2.noarch.rpm and ran the Redhat package manager install procedure (rpm -i some.rpm) on each.

    I now have lots of good fonts to work with in GIMP and can use a few fonts that look alright in Netscape. I'm not saying you should do exactly as I have, but at least these notes may illuminate how Redhat 6's default font functionality can be improved.
    Back to top


    I often forget the arcane commands of the Vi editor. Here's one that is useful:

    (escape) :% s/strin/strout/g

    That will sUBSTITUTE all instances of strin with strout in your document (g is for global -- without it only the fist strin is changed). That's all. If you are looking for a complete Vi reference, there's a decent book by O'Reilly on the topic.
    Back to top