GNU/Linux Quick Fix

This file contains a couple of answers to questions you might have when using a GNU/Linux OS.

  1. How do I examine a binary file?

    Use od -A x -w<length> -t x1 <file> where -A x says to print the file offset in hexadecimal, -w<length> says how many bytes per line we have and -t x1 says that you want the file interpreted as containing bytes.

  2. How do I copy a distribution CD file to a CD-ROM

    1. Find out the scsibus,target,lun of the CD recorder: cdrecord -scanbus. Choose the three numbers listed along with your CD recorder, for instance for
      	      0,0,0     0) 'HL-DT-ST' 'RW/DVD GCC-4241N' 'A100' Removable CD-ROM
      	    
      those numbers will be 0,0,0.
    2. Create a CD containing the image file: cdrecord -v dev=scsibus,target,lun <file>.
  3. How do I unpack a rpm file?

    Use rpm2cpio <rpm_file> | cpio -idmv --no-absolute-filenames.

  4. How do I copy a web site on the local machine?

    Use wget -r -p -k -np <URL>, where -r means to download the pages recursively, -p means to download all the page prerequisites and -k means to convert links such that the page can be viewed locally and -np means to not ascend to the parent directory. You might need to add a -e robots=off, to ignore sites that don't like robots.

    At this time, 2004-09-07 wget cannot download files larger than 2GB.

  5. How do I login to a remote computer without having to type the password

    The following method works if the remote computer has the same user name and password as the current computer.

    Generate a new RSA key using ssh-keygen -t rsa on the local machine, and then store the content of the generated file ~/.ssh/id_rsa.pub into ~/.ssh/authorized_keys on the remote machine. Sometimes, even if you do that, automatic login will still not work. The reason I have seen is that the file ~/.ssh/authorized_keys has write permissions for group, and sshd doesn't like this. A useful method for debugging the the connection is:

  6. rpm hangs when I try to install a program. How can I fix this?

    Kill any rpm process that you have running. Go to /var/lib/rpm and remove the rpm database files (rm __db.*). Rebuild the rpm database (rpm -vv --rebuilddb). For more information see Repair a RPM database.

  7. How can I print LaTeX source code?

    a2ps by default prints the document generated from your latex source. To disable that you have to type: a2ps --delegate=no <latex_file>. However, this didn't work very well for me as they were symbols that were still interpreted by a2ps.

    Better, use enscript with the following command that will print the LaTeX file in landscape mode with every line prefixed by its line number.

    enscript -2r --line-numbers=1 <latex_file>
    	
  8. How do I add a website to multiple search engines?

    Please check the answer listed here

  9. How do I setup direct/inverse search between emacs and the dvi viewer?

    This question refers to the ability to select in the viewer the paragraph you are editing in emacs and the ability to select in emacs the paragraph you clicked on in the viewer. To do that you have to use AUCTeX package with emacs and and the xdvi viewer. C-c C-c View command in emacs will start the viewer with the current emacs paragraph highlighted in the viewer, and Ctrl + left-click command in the viewer will move the focus on emacs and select the paragraph you clicked on.

  10. How do I analyze performance of Java applications?

    Use java -agentlib:hprof=cpu=samples,thread=y,depth=12 <class_file> to start your program with profiling enabled. cpu=samples means that the current stack frame of the program will be periodically sampled, thread=y means that the dump will include thread information, and depth=12 gives the number of functions that will be printed for a given execution frame. This will generate a file called java.hprof.txt. Examine the file with a text editor and with JPerfAnal by using the following command: java -jar jperfanal.jar java.hprof.txt. More informations at HPROf: A Heap/CPU Profiling Tool in J2SE 5.0 and PerfAnal: A Performance Analysis Tool. The NetBeans Profiler looks promising but it is not there yet as of 2005/10/08. Update (2007/10/01): I took another look at the profiler for NetBeans 5.5.1. While it is improved, it still seems to give me wrong results. HPROF + JPerfAnal is still the way to go for now.

  11. How do I copy fonts from Windows (to use them in Linux)

    Navigate to Start>Control Panel>Fonts. Write down the file names of the fonts you want to copy. Copy those files from %SYSTEMROOT%/fonts. See next question for instructions to install those fonts in Linux.

  12. How do I install An Aditional Font Directory?

    The answer at fedorafaq didn't work for me. I had to:
    cd /usr/share/fonts
    cp <source_font_dir> <font_dir>
    cd <font_dir>
    ttmkfdir
    mkfontdir
    chkfontpath -a /usr/share/fonts/<font_dir>
    fc-cache
  13. I installed a new version of openoffice, how do I change gnome settings such that the new version is used instead of the old one

    A quick and dirty solution is to edit /usr/share/applications/redhat-* and specify the path to the new version of the program. See Fedora Core 4 Desktop Gnome 2.10 and KDE 3.4 for a good description of the gnome file associations.

  14. How do I convert a OpenOffice.org document to PDF from command line?

    Use <openoffice.dir>/program/spadmin to setup a new software printer that converts openoffice.org documents printed to it to PDF. Type the following: New Printer.../Connect a PDF converter/Next/The default driver/Next/<select the command line provided>/Next/Finish Now you can print convert documents to PDF by typing at the command line: soffice -p 'PDF converter' <file>. The PDF file will be created in the PDF target directory or in the home directory if you left that field empty.

  15. How do I setup periodic checks on the file system

    It is always a good idea to setup periodic checks on the file system, especially since ext3 the journaling file system disabled those checks. I lost a couple of days reinstalling linux because errors were not caugth in time. Use this command to set checks every 30 mounts or every 6 months which ever is sooner on all /dev/hda drives that are not ntfs.

    for i in `mount | grep hda | grep -v ntfs | cut -d ' ' -f 1`; do tune2fs -c30 -i6m $i; done
    Use the following command to check the current parameters for all /dev/hda drives.
    for i in `mount | grep hda | grep -v ntfs | cut -d ' ' -f 1`; do tune2fs -l $i; done
  16. How do I print a label from OpenOffice.org?

    Use the templates from Worldlabel.com.

  17. How do I recompile the kernel?

    1. Download the latest stable kernel from kernel.org or one of the mirrors.
    2. Uncompress the kernel file in /usr/src: cd /usr/src;tar xjf linux-2.6.15.6.tar.bz2. This will create a directory /usr/src/linux-2.6.15.6
    3. Download and uncompress the source code for the current kernel, so that you can get its configuration file:
      • Download kernel-2.6.12-1.1381_FC3.src.rpm from download.fedora.redhat.com
      • Uncompress the sources: rpm -ivh kernel-2.6.12-1.1381_FC3.src.rpm
      • Apply patches: cd /usr/src/redhat/SPECS/;rpmbuild -bp --target=noarch kernel-2.6.spec
      • Copy a config file from /usr/src/redhat/BUILD/kernel-2.6.12/linux-2.6.12/configs/ to /usr/src/linux-2.6.15.6/.config
    4. Bring the config file up to date to match your new kernel: make oldconfig
    5. Make changes to the configuration (if you want to): make xconfig or make menuconfig
    6. Build and install the new kernel: make mrproper all modules_install install
    7. Make the new kernel the default one by changing the default value to 0 into /etc/grub.conf
    8. Reboot. If you have a binary driver (NVIDIA or ATI) you'll have to recompile that after you reboot by unloading X with init 3, recompiling the driver and than loading X with init 5
  18. How do I enable harware OpenGL in MATLAB?

    If you have a graphic card and a driver which supports OpenGL, MATLAB (version 7.0.1.24704 (R14) Service Pack 1 or later) should figure this out and enable hardware OpenGL by default. Check this by typing opengl info at MATLAB propt. If your driver works corectly but MATLAB still says that it uses software opengl, you might solve this by renaming <matlab>/sys/os/glnx86 to glnx86_old. This directory contains a bunch of older versions of libraries which are already available on your system. You will have to reload MATLAB to see any change. This fix worked with Fedora Core 3. For Fedora Core 5 I had to create a glnx86 directory and inside it, create a link to libXm.so.2 to ../glnx86_old/libXm.so.2

  19. How do I run tests on a remote machine without the need of keeping an open terminal to the remote machine?

    Linux Server and Client

    VNC Server starts a new X Server on the 'remote-host' where you can display the results of your programs, in general tests that run for a long time. The advantage is that those programs don't need to be connected to your 'local-host', but you still can see their output from time to time. Unfortunately, that X Server doesn't know OpenGL.

    On the 'remote-host', as 'root' you'll have to set VNCSERVERS to "1:user" in /etc/sysconfig/vncservers. As 'user' setup the VNC password by calling vncpasswd. As 'root' start the VNC server by typing service vncserver start.

    From the 'local-host' you can connect to the remote-host's new X server by using vncviewer remote-host:1 and by typing the password you just setup. If your gateway allows only ssh trafic, you can use vncviewer -via remote-host remote-host:1 to connect to the remote-host.

    Windows Client

    Install CYGWIN and make sure you select openssh package and install RealVNC

    Securely forward port 5911 (you can choose any port here) on the local-host to port 5901 (the default port for VNC) on the remote-host: ssh remote-host -L 5911:127.0.0.1:5901

    Modify the shortcut for vncviewer to read vncviewer.exe 127.0.0.1:5911

  20. How do I save a html page as a text file

    Usually this is usefull if you want to process that web page through a script. Install links web browser and once you loaded the web page you can do ESC to show the menu and then File>Save formatted document

  21. How do you execute diff and ignore changes in amount of white space in subversion

    svn diff --diff-cmd /usr/bin/diff -x "-b" <file>

  22. How do I activate changes made to .Xresources

    Execute xrdb -merge ~/.Xresources

  23. I added a new Latex package. How do I activate it?

    Run texhash as root.

  24. I want to learn to touch-type. What program do I use?

    Use gtypist. You can install it using yum install gtypist

  25. I want to print a calendar for the whole year. What do I do?

    You can use the calendar program in emacs. M-x calendar. Then you can print a yearly calendar in various formats. For instance to generate a calendar in LaTeX you type t y. You have to save that buffer in a file C-x C-w <file>

    and then compile the file to DVI and print the file.
  26. How do I mount a filesystem through ssh?

    You can use sshfs user@system:path mountPath

  27. How can I allow a file system to be mounted and unmounted by a user

    In /etc/fstab, you have to replace defaults with user for that file system.

  28. How do I generate a random file on linux

    The following code generates a 1GB file. dd if=/dev/urandom of=gb_file bs=1MB count=1000 If the file you want to generate is pretty small use bs=size and use count=1.

  29. How do you convert a file between DOS and Unix format

    There are two utility programs dos2unix and unix2dos that can do that.

  30. How do you use Latex formulas in xfig

    This is adapted from http://www.math.umd.edu/~jkolesar/latexandXfig.html and http://www.eg.bucknell.edu/physics/ph329/xfig_latex.html

    Inside xfig, add the LaTeX expressions to the figure, using $...$ to switch to math-mode where necessary. Use the normal method in xfig for adding text, but set the special text mode using the Text flags menu at the bottom of the screen.

    Add the following entry to your .bashrc file:

    xfig2eps ()
    {
        if [ $# -ne 1 ]; then
    	echo "${FUNCNAME[0]} <xfig_basename>";
    	return;
        fi
    
        echo \
    	"\documentclass{article}
    \usepackage{amssymb,amsmath,graphics,epsfig,color}
    \pagestyle{empty}
    
    \begin{document}
    
    \begin{figure}
    \input{temp.pstex_t}
    \end{figure}
    \end{document}" > $1.tex;
    
        fig2dev -L pstex -F $1.fig > temp.pstex
        fig2dev -L pstex_t -p temp.pstex $1.fig > temp.pstex_t
        latex $1
        dvips -E -o $1.eps $1.dvi
        rm $1.tex $1.aux $1.dvi $1.log temp.pstex temp.pstex_t
    }

    Run the the following command to generate the eps file from the xfig file

    xfig2eps fig1.fig

    You should now have a file named fig1.eps which can be included in other LaTeX documents.

  31. I want to show files in a directory on the web but Apache Web Server fails with the error Directory index forbidden by Options directive. How do I fix this?

    You will have to modify /etc/httpd/conf/httpd.conf and change:

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    	

    to add Indexes in the list of options like this: Options Indexes FollowSymLinks