Thursday, August 10, 2006

How to list just directories in bash

This morning, I was trying to find a way to list just the subdirectories in the current directory, in a bash shell script I was writing. I thought it would be simple, but everything I tried seemed to either take an extraordinarily long time, or felt like an ugly hack.

The first thing I tried was:
find . -type d

But this was extremely slow, because it was recursively searching inside every subdirectory as well. I just wanted a list of subdirectories inside the current directory. I won't bore you/clutter this post up with any more of my less-than-ideal methods.

What follows are a couple of ways of doing what I was trying to do, which I found in a post (and its comments) on the Ubuntu Blog, "List only the directories":

ls -l | grep “^d”

This works, but gives a 'long' directory listing, when all I wanted was a list of directory names.


find . -type d -maxdepth 1 -mindepth 1

This one was my favorite, since it used the method I originally tried, but it fixed the slowness by using parameters to avoid recursion. It gave me a couple warnings about the order of the parameters, though, so I changed it to this:
find . -maxdepth 1 -mindepth 1 -type d

ls -d */

This gave me the same output as the 'find' method did, but some timing tests showed me that the 'find' method was about 2 times faster.

Monday, August 07, 2006

A Handy CSS Debugging Snippet

From A Handy CSS Debugging Snippet:

* { outline: 2px dotted red }
* * { outline: 2px dotted green }
* * * { outline: 2px dotted orange }
* * * * { outline: 2px dotted blue }
* * * * * { outline: 1px solid red }
* * * * * * { outline: 1px solid green }
* * * * * * * { outline: 1px solid orange }
* * * * * * * * { outline: 1px solid blue }


This code, if placed in your stylesheet, outlines every element on the page with colored boxes. I like this because it's simple, and I learned something from it. I had no idea that you could use an asterisk for a css selector. Then, the idea of stringing them together to represent the elements that are most deeply nested with different colored outlines. Pretty slick!

I will probably still use the many functions in the Outline menu of the Web Developer Extension for Firefox, and the Internet Explorer Developer Toolbar, for most of my everyday outlining-for-debugging needs. There are also bookmarklets out there to do this type of thing. But, this snippet deserves a spot in my toolbox, because it seems like it could could come in handy someday.

Friday, August 04, 2006

Disabling Message Center in RealPlayer via a simple registry edit

Random tidbit of potentially useful information...

From a comment by Wulf on the Google Operating System blog:

While playing around in my Registry, I found an interesting entry from RealPlayer.

If you change
HKEY_CURRENT_USER\Software\RealNetworks\Msg\
Preferences\Frequency > (default)
from 1 to 0, the 'Message Center' (read: ads) won't come up anymore...

I haven't tried this, as I so rarely use RealPlayer that I don't even remember the annoyance that this tip claims to prevent. But, I did go ahead and make this registry value change, in the hopes that someday, something might less annoying. :)

I actually took this opportunity to try out REG.EXE, the "Console Registry Tool for Windows" (it came with Windows XP Pro), which I've never gotten around to messing with... So this is how I changed this particular registry key:
reg add
HKCU\Software\RealNetworks\Msg\Preferences\Frequency
/ve /d 0