set -o vi FTW

The Bash command line can be edited using the cursor keys but for the real power user you need to enable Vi mode:

$ set -o vi

Or add it to one of your Bash startup files.

Now, instead of the slow interactive editing you’ll get the command and insert mode of Vi! Users of Vi or Vim will feel right at home. You start in insert mode by default so it feels the same as before. You can type new text, move left and right with the cursor keys and delete text but press ESC and you can do all the things Vi command mode allows you to do.

Check out this extensive cheat sheet with examples or jump directly to the ascii version here!

Some tips to make Mac OS X Finder easier to use

Making the switch from Windows or Linux to Mac OS X is not without pain. The extra CMD key plays havoc with muscle memory, and the “Windows Explorer” of Mac OS X, Finder, is quite a different beast to what you might be used to in the Windows or Linux worlds.

About two weeks ago I decided to make the switch again to Mac OS X and I lamented the difficulty in using Finder to do simple tasks. I’m still not 100% happy with Mac OS X it but the tips on the following pages made things easier:

  • Home and End keys work on a line, not a document, silly.
  • Disable natural scrolling.
  • Switch CMD and ALT if you’re using a PC keyboard. I have a lovely split keyboard but the default configuration hurt my fingers.
  • Change the keyboard layout if your keyboard doesn’t work the way you’re used to. I still haven’t got this set up exactly as I want it to. In my terminal some keys act differently I think but I haven’t set aside time to work out which. I need to swap ” (shift-2) with @ (key to the top/left of right-shift). My muscle memory gets them mixed up all the time.
  • Automount SMB drives automatically. I haven’t been able to get the fstab method to work yet because my password has spaces but the “User Login” one works well enough.
  • Change Finder search so it searches the current directory by default.
  • Type the path into Finder.
  • 9 tips to improve Finder.
  • Sorting and arranging in Finder.
  • Right click on the directory name in Finder and show a dropdown of the path to that directory.
  • Install Mac Ports to get a working copy of Rsync and a better ls that lets me put parameters after the filename.

There are still oddities. When Mac OS X mounts an SMB share it does so with permissions that only allows the current user to edit files in the share. That’s perfectly understandable but it messes things up for Rsync when I’m syncing directories with a remote host. I’ve had to resort to using the “–size-only” parameter of Rsync so it won’t attempt to sync every file each time. I need to figure out if that can be fixed somehow.

I’ll update this post from time to time as I come across more oddities.

PHP Notice: Undefined variable: _SERVER in ..

I upgraded Linux on this server a while back and in the course of that upgrade PHP was upgraded too, to version 5.5.9.

Since I had a modified php.ini it asked me to check over any new options. There were a few but I fixed anything that looked like it might break things. I saved the php.ini and let the upgrade go on.

Clearing up bugs

Some time later I saw odd notices in the PHP error log. Usually it referred to wp-comments-post.php but files outside of WordPress raised the warning too:

PHP Notice: Undefined variable: _SERVER in ..

It turns out the fix is rather easy. Jacques Marneweck on his blog posted a solution. Simply switch off “auto_globals_jit” in your php.ini and restart Apache (if required).

From the PHP manual entry for auto_globals_jit:

When enabled, the SERVER and ENV variables are created when they’re first used (Just In Time) instead of when the script starts. If these variables are not used within a script, having this directive on will result in a performance gain.

The PHP directives register_globals, register_long_arrays, and register_argc_argv must be disabled for this directive to have any affect. Since PHP 5.1.3 it is not necessary to have register_argc_argv disabled.

A bug

It looks like the bug is ancient although I’m not using APC, and the JIT compiler can be fooled if you access the super globals like _SERVER through variable variables. Sneaky!

The default for auto_globals_jit is “On” so next time you upgrade PHP keep an eye on the error log.

Go on back to Linux will ya!

I’m back in the world of Linux on my desktop machine again. Well, mostly.


Desktop Linux has been a “thing” for so long now it’s a cliche but I used it as such for well over a decade and it wasn’t until I was lured away by the shiny games offered by Steam that I installed Windows on a machine. Well, time passes and Linux support for games improves. Many fabulous indie games now have Linux versions. I’m glad I can play Kerbal Space Program, Prison Architect, Papers Please, Luftrausers and more without booting into Windows!

I’m mostly back in the Linux fold. There are still apps I use regularly that don’t work in Linux. Lightroom and Ynab are the main offenders. Both run to a certain degree in Wine, and the latter runs quite well, but I’m afraid I’ll be cheating on Linux. I have a Macbook laptop here too that runs Lightroom just fine. My 1TB of photos (and some videos) resides on an external drive in my Linux box but with the catalog copied over to the laptop, Lightroom runs reasonably well.

It hasn’t been plain sailing either. I corrupted one external drive when I let Ubuntu try to resize and partition it. It was probably my own fault for not defragging it first. I thought I had lost everything as Windows couldn’t see anything on it. Luckily, after booting into Linux on a USB flash drive I could see everything I wanted copied off.

I have an Nvidia graphics card and I noticed ugly tearing in web pages in Chrome. I found a page that suggested enabling “Override software rendering list” in chrome://flags/ but while that worked it also stopped my cursor changing when hovering over links and hover actions on menus didn’t register. Luckily I found this thread that suggested disabling the “Composite” module in the X server. (That’s the program that displays things in Unix)
I couldn’t find the file, /etc/X11/xorg.conf in my Ubuntu 14.04 install but I found Composite was mentioned in /etc/compizconfig/unity.ini and when I removed it, restarted X and logged in again Chrome scrolled like melted butter on hot scones. (yum)

Unity is a lot nicer than I remember it, or maybe it’s because I have a better machine now. I have no doubt I’ll get bored of it and start installing Gnome, KDE, Xfce and everything else to play with, before coming back to it again. I fondly remember the days of Windowmaker.

So, Linux is back.

Linux: when the /boot is all full

I tried to install fdupes this morning on my Ubuntu Linux server but the install bombed out with this error, followed by a string of other warnings before dpkg rolled back everything:

gzip: stdout: No space left on device

What? I’d installed a 500GB drive in that machine recently. It was /boot/. A quick look in there revealed a number of old Linux kernels but luckily there’s an easy way to get rid of them.

This showed me a list of all my installed kernels, and “uname” told me the name of the current kernel which I shouldn’t remove.

dpkg -l linux-image-\* | grep ^ii

Removing them was as easy as this:

apt-get purge linux-image-3.8.0-29-generic linux-image-3.8.0-31-generic linux-image-3.8.0-32-generic linux-image-3.8.0-33-generic linux-image-3.8.0-34-generic linux-image-3.8.0-35-generic linux-image-3.8.0-36-generic

When I finally installed fdupes it kindly removed all the kernel headers saving me a further 505MB of space. I’m pretty sure this is the first time /boot has filled up on me.

fdupes is pretty nice too. It finds duplicate files by comparing file sizes first and then does MD5 checks.

Fix file (644) and directory (775) permissions in Linux easily

A few weeks back I was sorting out the drives on my Linux server and as some of the directories were created through various configurations of Samba by Windows clients the permissions were a bit odd. Some archive files were executable, some directories were rw only for the owner. You get the idea, it was a mess. How do I fix them quickly?

I’d like all the files to be 0644 and directories should be 0775 please. Oh, and I’d like all that done with the minimum of fuss through a Bash shell, with or without a cherry on top.

Luckily I’m not the first person to ask this as user stress_junkie in this thread had an answer:

For directories only do this.

find . -type d -exec chmod 775 {} \;

For files only do this.

find . -type f -exec chmod 664 {} \;

There’s also this useful chunk of code to avoid hitting . and .. but I didn’t care about that in my case so the above code worked perfectly:

find . -type d -name \* -exec chmod 775 {} \;

And finally, user Gethyn pointed out that this command will add execute permissions to directories.

chmod -R +X

I have a feeling I’ll be coming back to this post in the future, just like I’ve had to check my directory comparison post a couple of times recently.

Do more with your old MacBook

Have you got an old MacBook that Apple doesn’t support any more? Can’t install the latest and greatest version of Mac OS X on it because the CPU is too old? You’re probably seeing a warning from Chrome that Google has discontinued support for Mac OS X 10.5.3 or whatever is on that ancient beast? It’s the same with Firefox.

Flash isn’t updated either and when you go to Youtube to watch a video Chrome shows you an ugly warning that it’s outdated. Frustrating isn’t it?

What’s more, you’re probably leaving yourself open to exploits by nasties on the Internet. Problems and bugs are found in Flash all the time. Browsers and operating systems are the same too but if that software isn’t actively updated then you’re out of luck. I discovered Opera browser is still built for these old machines and it’s fast but Flash was still a problem and I needed a better solution.

As unlikely as it may seem on an Apple computer, it’s Linux that came to the rescue!

I didn’t think I could put Linux on the MacBook as there was no Bootcamp to dual boot the machine. Thanks to I found the MacBook help pages for Ubuntu which pointed me towards rEFIt, a “boot menu and maintenance toolkit for EFI-based machines like the Intel Macs.” Even on an old MacBook 4,1 I could install Linux!

Installing rEFIt was simple enough, just run the package installer when I mounted the .dmg file. However the boot menu didn’t appear, even after several reboots until I pressed down ALT while rebooting.

Partitioning was a problem. I used the command line diskutil tool as suggested here but ran into problems because it couldn’t do a live resize. It would report that it ran out of space or there were too many deep links. Luckily the Ubuntu install CD comes with Gparted and after booting into the live CD I ran that and freed up 40GB of space for my new Linux install. A couple of reboots later to verify everything was working and then on to Linux!

Thankfully I didn’t run into the problems a recent Ars reviewer of Ubuntu Linux 12.10 came across. Linux installs are getting simpler and simpler. I told it to install alongside Mac OS X and let it set up partitions.

The WIFI adaptor in the Macbook requires a proprietary driver and after hooking the laptop up to an ethernet cable I started updating packages. While doing that I looked in the System settings and discovered that Ubuntu had installed the right driver without my prompting! I’m not sure when that happened but WIFI has been rock solid since.

Time to install Opera, the restricted packages (mp3 and dvd playback, etc), Java for Minecraft and finally Minecraft. Getting a Minecraft icon for Unity was a pain and I can’t find the script I used now but some quick Google-fu will find it.

Linux on the MacBook is nice and fast, even with Unity on there. I may replace that with a lighter window manager if it becomes a problem but it’s much improved on older releases. If you have an old MacBook and you don’t need some proprietary software that isn’t available for Linux then you should definitely put Linux on there. You’ll have the security of using updated software and a nice new desktop and apps to play around with!

Bash: compare two directories

In Unix based systems like Linux and Mac OS X there are a number of ways of comparing two directories. The simplest way is to use diff:

diff –brief -rb directory_1 directory_2

This command compares each file and reports if they differ. You can find the meanings of the options in man diff.

Diff is fine if you’re on a fast drive, if there aren’t many files or the files aren’t big. The command compares the contents of each file so it can take quite some time on a slow external drive.

If you just want to know which files are in one directory and not in the other directory it’s overkill. This little bit of Bash scripting does that however:

diff <(cd dir1 && find | sort) <(cd dir2 && find | sort)

It still uses diff, but compares the file listing of each directory instead of the files. It’s much faster and perfect for figuring out what files are out of place on my 2 relatively slow USB drives. (source)

Where does Nautilus store it’s folder share info?

Using a GUI is nice and all but sometimes I want to know where configuration data is stored.

The Gnome file manager, Nautilus, allows Linux users to share folders on a Windows network. Users of other operating systems will find this hard to believe but before this it was difficult to do as you needed to be an administrator and edit a configuration file called /etc/samba/smb.conf (Users of other desktop managers use similar tools).

This was convenient but I wanted to know where Nautilus puts this configuration data. I searched my home directory, I looked in /etc/samba/ (just in case) and eventually found this page:

I located the config files.

It appears as though /var/lib/samba/usershares holds a text file for each share that has been created.

The usershares directory is owned by root:sambashare and the files inside are owned by the user sharing the folder, so I guess it’s a compromise between a system process (Samba) and users wanting to configure it.

Editing those files is simple, and I guess I could use “net usershare” too. I had to restart Samba too which probably wouldn’t be needed if I had use the “net” command.