Adventures in Unix

Here you can read all about the fun of configuring things!! This is such exciting and controversial reading, that I've already been approached by several publishers looking to print my works. Sadly, I mostly use OS X these days, and don't really find myself configuring anything.

Use ssh keys for login

On client:
ssh-keygen -t rsa -b 2048 \
cat ~/.ssh/id_rsa.pub | ssh -e none server 'cat >> ~/.ssh/authorized_keys'

Use git for regular diffs

To use git for color and word diff, add a script to your bin directory:
#!/bin/sh
NOT_IN_REPO=--no-index
COLOR_WORDS=--word-diff=color
IGNORE_ALL_WS=--word-diff-regex=[^[:space:]]  #or -w
git diff ${NOT_IN_REPO} ${COLOR_WORDS} ${IGNORE_ALL_WS} $@
Or as one line:
#!/bin/sh
git diff --no-index --word-diff=color -w $@

Find files in date range

Find files newer than first date and not newer than second date:
find . -newerct "2015-02-25" ! -newerct "2015-03-10"

Convert git repo to bare

Go to the repo location in your shell.

git config --bool core.bare true
mv .git ../NEWNAME.git

Delete the original repo.

Combine two seperate git repos

I needed to merge two repos into one. Other people have had similar needs. The basic idea is:

Add the remote repo:
git remote add remote_branch remote_repo_location
Pull the changes into the local branch:
git pull remote_branch current_branch

Recover data on failing disk

Bottom line is use ddrescue. It will recover as much data as possible in the shortest time possible. John Gilmore has already written how to use this tool effectively. Remember, freezing your disk might let you get that last bit of data.

Also, having SystemRescueCd or (R)ecovery (I)s (P)ossible Linux around for smartctl and badblocks will help. Dump the image to a USB stick for easy use:
dd if=image.iso of=/dev/usb_device bs=1m

Make git work on a new machine

Set editor, colors, and disable idiot-proof CRLF.

git config --global color.ui true
git config --global color.branch true
git config --global color.diff true
git config --global color.interactive true
git config --global color.status true
git config --global core.editor "vim"
git config --global core.autocrlf false

Remote diff with rsync

Need to diff things over the network? Here's an easy way. Adapted from ZuhaiBlog. This is not a bidirectional diff; you need to run it twice, swapping source and dest to find all differences. It would probably be worth using unison or csync if those tools become more widespread.

rsync -n -rvc user@server:/source/ /dest/

Note the trailing slash on the source directory! This is needed for recursive diffing.

The -c option compares using checksum, this can be very slow for large files, so remove as needed.

The -n (also --dry-run) option enables dry-run, do not remove it!

Fonts too big/small in Inkscape, Gimp, and X11 in general

When using OS X, the X11 fonts seem too big sometimes. Inkscape can be really bad. You can control the font size by setting the XServer's display DPI.

Just edit /usr/X11/bin/startx and set defaultserverargs="-dpi 75". Smaller dpi values result in smaller onscreen fonts. See this for details.

Command not found is slow

The package 'command-not-found' is installed by default in Ubuntu. If you type the name of an executable that is not installed, it helpfully suggests the package that supplies the command. Great... kinda.

Timings from a dual core 2.2Ghz machine (average 3x):
time ls
real	0m0.004s
user	0m0.000s
sys	0m0.000s

time not_installed_binary
real	0m0.202s
user	0m0.150s
sys	0m0.030s

time non_existant_binary_name
real	0m0.230s
user	0m0.163s
sys	0m0.047s
Timings from a 1.6Ghz netbook (average 3x):
time ls
real	0m0.017s
user	0m0.008s
sys	0m0.009s

time not_installed_binary
real	0m0.699s
user	0m0.540s
sys	0m0.156s

time non_existant_binary_name
real	0m0.701s
user	0m0.565s
sys	0m0.129s
Hey! Wow! Those timings are awful! Every time I make a typo, I pay almost a full second of doing nothing. At the time of writing, nearly every netbook uses this same processor. So why was the decision made to include this package in the default Netbook Remix install? Great recipe for frustration: slow processor, tiny keyboard, and a cost for typos. Maybe the goal is to create better typists?

Anyway, the fix is:
apt-get purge command-not-found command-not-found-data

DVI output not working when using ATI's fglrx drivers in Debian AMD64 (Black screen of death)

It seems the fglrx driver has some problems turning on the DVI connection? When X starts, I get a blank screen and my monitor goes to sleep. Here's my terrible solution. After X starts, push Alt+Ctrl+F1 to go to the first tty console- this should work on most setups. Then go back to the X console (Alt+left arrow, or Alt+F7). The monitor should now wake up. I'm using xdm, a Dell LCD, and I have DPMS turned on in the my XConfig. If the monitor goes to sleep, you'll have to do the fix again.

Using ATI's fglrx drivers in Debian AMD64

I think I needed these packages:
debhelper
module-assistant
kernel-package
xlibs-dev
xlibxtst-dev
libstdc++5
gcc
linux-headers-xxxx
Download the ati packages. Run ati-installer --buildpkg Debian-unstable (adjust as needed- use --get-supported).
Install the debs the installer creates.
Create the kernel module.
Run the aticonfig thing.
Be sure to disable the Composite extension in your xorg.conf

Good links:
Gentoo ATI Radeon FAQ
ATI Linux driver packages for Debian
Debian Installation Guide
ATI has some FAQs that might be useful- ATI

Can't set root background when using xcompmgr

When I first started using xcompmgr, it would replace my wallpaper with a grey background. If I ran qiv -x someimage to set a root image I would get this error:
qiv: Your root window's visual is not the visual Imlib chose;
     qiv cannot set the background currently.
Using the feh program instead of qiv to set the root image fixed the problem. Maybe this is because feh links to imlib2?

Cannot ping 127.0.0.1

Silly problem. If you find yourself unable to ping localhost or 127.0.0.1, this simple thing might fix it. Install the network loopback device. First, check if its already installed by running ifconfig as root. If you have the loopback device installed, you should see this:
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:30 errors:0 dropped:0 overruns:0 frame:0
          TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:4416 (4.3 KiB)  TX bytes:4416 (4.3 KiB)
Ok... if you don't have that stuff, then you need it. If you have debian, just do ifup lo. If you run some other *nix (heaven forbid ;), ifconfig lo up should do the trick. Either way, you probably want it to be installed on every boot up- stick one of those commands in /etc/init.d/network, or wherever your flavor keeps it's network init script (maybe /etc/network/interfaces ).

This fixes weird problems with mozilla or firefox not being able to upload files as email attachments or whatnot. There's probably other weird things that happen if you can't ping you.

ping: unknown protocol icmp.

Hmmm... add icmp 1 icmp to /etc/protocols to fix your precious pinging.

Apache - mod_bandwidth

This took a long time and turned out to be really simple. I wanted to use mod_bandwidth with Debian woody, so I added all the stuff to my httpd.conf and tested it out. Of course, it didn't work and neither did the BandWidthDataDir directive. After a little searching, I noticed that it was adding a line to my apache error log (in /var/log/apache/error.log) every time I tried getting a file handled by mod_bandwidth. The error looked like this: [error] (2)No such file or directory: mod_bandwidth : Can't create/access master file /var/state/apache/mod-bandwidth/master/ (followed by some numbers).

So I tried making the 'master' dir and adjusting all the permissions, but it still didn't work. After going through the error logs again, I finally noticed that the module was looking for "mod-bandwidth" and I had "mod_bandwidth" on my disk. After renaming the dir and adding a 'link' directory to it (so it contains link and master), everything worked.

Here are the additions to my http.conf

LoadModule bandwidth_module /usr/lib/apache/1.3/mod_bandwidth.so

......

<IfModule mod_bandwidth.c>
    BandWidthModule On

    #this didn't work
    #BandWidthDataDir "/tmp/apachebw"

    #this is the default
    #BandWidthPulse 1000000
</IfModule>

<Directory /var/www/music>
    #local machines have no restrictions
    BandWidth 137.112 0

    #everyone else gets 20k/s
    BandWidth all 20480
</Directory>

Enlightenment 16 - tricks/tips

Holding down alt and double middle clicking maximizes a window vertically. Nice for long text files in a terminal.

To stop Enlightenment from eating mouse clicks combined with alt: hold down ctrl, then press alt, then click the mouse button. Very handy for the GIMP.

To make a wallpaper show up after copying it to ~/.enlightenment/backgrounds, just restart Enlightenment (middle click menu or ctrl+alt+end).

Right click dragging on window borders will move the window.

Putting background images in their own directory in ~/.enlightenment/backgrounds will make them have there own sub-menu when you middle click and go to Desktop > Backgrounds.

Don't forget the alt or ctrl+middle click on the desktop to bring up the job list.

Use the programs e16menuedit and e16keyedit to configure those parts of Enlightenment.

Enlightenment will continue to update the screen during moves/resizes if you select opaque method for them; in any other move/resize method, it will lock the screen.

You can move between desktops using the mouse's scroll wheel.