Category Archives: Linux

Learning more about Vim

I mentioned in a tweet recently that I’ve been using some form of Vi for about twenty years. It all started in college where we had highly advanced green screen monitors attached to a large Unix box. I can’t remember what Unix it was ran on that machine (it may have been UnixWare) but it was a far cry from the nice GNU interface we’re used to on modern Unix systems. Vim certainly was not a part of the default install.

However, Vim has been my editor of choice all my working life. All this time I’ve known I’m only scratching the surface of it’s functionality but only recently has it become clear how much. I can navigate through it with ease, open numerous files in separate splits, search/replace and of course vimdiff was partly responsible for every single WordPress MU release as I used it to pull over changes from WordPress.

So, thanks to /r/vim I discovered the following today:

  1. /r/vim_magic is indeed full of magic.
  2. More Instantly Better Vim is a great talk on some insane things to do with Vim.

  3. I had no idea Vim had tabs but I still prefer splits.
  4. snipMate.vim is a snippet plugin for Vim based on the snippets in TextMate. Around the turn of the century I had messed with abbreviations but this is way better. Found that here where there’s plenty more tips to read.

  5. Coming home to Vim is the story of the return of a TextMate user to Vim. Why didn’t I know about daX and diX?
  6. Since I use split files, I’m always tapping CTRL-w w or CTRL-w UP/DOWN to switch between splits. It never occurred to me that I could map the TAB like this to switch split files. TAB switches to the next split file, SHIFT-TAB hops back.

    map <Tab> <C-W>w
    map <S-Tab> <C-W>p

  7. I am tentatively mapping ; to : with nnoremap ; : but I probably won’t use it. My fingers are too used to LSHIFT-; to stop now. I’ve never used the ; command, I had to look it up to see what it did!

From my tweet comes some productivity tips. I have never used the Leader key. The shame, the shame!

So much to learn. I’ll probably leave comments on this post linking to all the bits and pieces I find. Yes, I’m excited about a bloody text editor. Haha!

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.

Mount box.net drives in Linux

I was one of the lucky few to receive a 50GB upgrade from box.net, (or box.com where they now live, marketing fail?) when I installed their Android app. I don’t have a use for that much storage on my phone but on my desktop machines? Oh yes!

This forum post describes in detail how to mount a Box drive on a Debian/Ubuntu machine although the instructions will mostly apply to other systems too as long as they have the davfs2 package.

There is a gotcha. Instead of using http://www.box.net/ you can use https://www.box.com/ which is a good gotcha. Also, I’m not the only person to notice that the mount point has a lot less storage than I thought it would have. It should be 50GB total but this is what I see from df -h:

https://www.box.com/dav 26G 13G 13G 50% /mnt/box.net

It’s enough for my needs. I’m going to copy snapshots of my local email there every night.

PS. Are you a Windows user? Sync any folder with Google Drive using the instructions here (but it uses “hardlinks” which have limitations, read the comments for more).
Actually, forget what it says in that post. Copy your files to your Google Drive and then place a symlink on your local drive to the copied files or folders using mklink. Make sure you run cmd.exe as an Administrator. I found this worked perfectly to sync the Pictures folder after I had copied it to my Google Drive:

cd c:\Users\USERNAME\
mklink /d Pictures “c:\Users\USERNAME\Google Drive\Pictures”

Any files copied into the Pictures folder are copied to the Google Drive now!

Install Ubuntu on your Android Phone

With this app you can install Ubuntu on your Android phone. It has to be rooted obviously and it’s definitely not this.

It looks like this installs Ubuntu in the same way as in the video above. It’s an app that runs in the background and you use a VNC client to connect to it. You could of course use VNC on a local desktop machine to connect to it too making it more useful but I think this is more a curiosity for those who like to tinker with their phones …

Pity he couldn’t get WordPress running on that Ubuntu install. That would have been fun to see!

Howto: Install XFCE in Ubuntu 11.10

You realise how spoiled you are by the ease at which software can be installed in Linux only when you’ve done the same in Mac OS X or Windows. apt-get or aptitude will install a wide variety of software and in the case of aptitude will remove the software and all it’s dependencies afterwards.

Yeah, I’m saying goodbye to Unity and embracing XFCE (for the moment at least. Choice is good!)

# aptitude install xfce4 xfce4-goodies
The following NEW packages will be installed:
desktop-base{a} exo-utils{a} gtk2-engines-xfce{a} hddtemp{a} libexo-1-0{a} libexo-common{a} libexo-helpers{a} libgarcon-1-0{a} libgarcon-common{a} libkeybinder0{a} libtagc0{a} libthunar-vfs-1-2{a}
libthunar-vfs-1-common{a} libthunarx-2-0{a} libtumbler-1-0{a} libxfce4ui-1-0{a} libxfce4util-bin{a} libxfce4util-common{a} libxfce4util4{a} libxfcegui4-4{a} libxfconf-0-2{a} lm-sensors{a} mousepad{a}
orage{a} ristretto{a} squeeze{a} tango-icon-theme{a} thunar{a} thunar-archive-plugin{a} thunar-data{a} thunar-media-tags-plugin{a} thunar-volman{a} tumbler{a} tumbler-common{a} xfburn{a}
xfce-keyboard-shortcuts{a} xfce4 xfce4-appfinder{a} xfce4-artwork{a} xfce4-battery-plugin{a} xfce4-clipman{a} xfce4-clipman-plugin{a} xfce4-cpufreq-plugin{a} xfce4-cpugraph-plugin{a}
xfce4-datetime-plugin{a} xfce4-dict{a} xfce4-diskperf-plugin{a} xfce4-fsguard-plugin{a} xfce4-genmon-plugin{a} xfce4-goodies xfce4-mailwatch-plugin{a} xfce4-mixer{a} xfce4-mount-plugin{a}
xfce4-netload-plugin{a} xfce4-notes{a} xfce4-notes-plugin{a} xfce4-panel{a} xfce4-places-plugin{a} xfce4-power-manager{a} xfce4-power-manager-data{a} xfce4-quicklauncher-plugin{a} xfce4-screenshooter{a}
xfce4-sensors-plugin{a} xfce4-session{a} xfce4-settings{a} xfce4-smartbookmark-plugin{a} xfce4-systemload-plugin{a} xfce4-taskmanager{a} xfce4-terminal{a} xfce4-timer-plugin{a} xfce4-utils{a}
xfce4-verve-plugin{a} xfce4-volumed{a} xfce4-wavelan-plugin{a} xfce4-weather-plugin{a} xfce4-xkb-plugin{a} xfconf{a} xfdesktop4{a} xfdesktop4-data{a} xfwm4{a} xfwm4-themes{a} xscreensaver{a}
0 packages upgraded, 82 newly installed, 0 to remove and 0 not upgraded.
Need to get 40.9 MB of archives. After unpacking 144 MB will be used.
Do you want to continue? [Y/n/?] y

Once installed, logout and select XFCE from the login menu.

XFCE has it’s own quirks and gotchas but it feels lighter and more responsive than Unity. The most difficult part was making the top menu bar autohide. I had to remove the “running programmes” list to get at the panel preferences. Only later did I notice the “Panel” item when you right click some of the menu widgets. The full screen mode in Gnome Terminal gets me back the extra 2-3 lines of terminal I missed. So winning all around as a certain actor once said …

Installing Gnome 3.2 is just as easy and looks gorgeous!

aptitude install gnome-shell