Alvin Alexander | Java, Scala, Unix, Perl, Mac OS X

Working on my Mac OS X system, when I use the ls command on a remote system, that system is configured to show blinking text for all files ending with the ".sh" filename extension. If you've ever had to look at blinking text when trying to read output from an ls command you know that can be really annoying. (Is there ever a time that blinking text isn't annoying?)

So, to disable blinking text in the Mac OS X Terminal application just follow these steps:

Mac DVD burn FAQ: How do I burn a CD or DVD on a Mac? (iMac, MacBook, Mac Pro, etc.)

It's funny, I've had a MacBook Pro for well over a year now, but haven't burned a CD or DVD until today. I actually didn't know how to do it, so I just inserted a blank DVD-R into the drive and then figured out what to do. Here's a quick summary of the "Mac CD/DVD burn" steps I followed.

Working on a Unix system, I just needed to reverse the contents of a file, and thought I'd show how I ended up doing it.

My file-reversal needs

For my situation I needed to (a) get 10 lines from the end of a file, (b) reverse those ten lines, and (c) save them to another file. If my Unix system supported the -r option of the tail command this would have been a no-brainer, but it didn't, so I had to work a little harder.

After a few requests/suggestions I've added digg links to the blog pages. So, if they all say "0 diggs", hey, it's a new feature. :)

The Linux tar command is used to created and extract archives. An archive is one file that contains one or (usually) many other files. The name "tar" itself comes from the phrase "tape archive", but that's just an old name. I mostly just create archives and then send them over the wire these days.

Creating Unix/Linux tar archives

To create an archive of all files in your current directory, and all subdirectories, use this tar command:

The other day, when I was trying to compile all the Tame Swing examples, I had a problem running one of the examples. The problem was that I was running the example in Eclipse, and I was getting an error message showing the Eclipse (the JVM really) couldn't find the icon image files.

Linux/Unix more command FAQ: Can you share some Linux more command examples?

The Unix/Linux more command lets you scroll through large files, or large amounts of output from other commands.

Linux more command examples

To scroll through the contents of a large file named "large_file" you can use the Unix more command like this:

more large_file

As a quick aside, I see a lot of people use the Linux cat command and more commands this way:

The Linux locate command lets you easily find files in the filesystem. It works by maintaining a system-wide database of "all files which are publicly accessible". The database itself is updated periodically by a background process. Because of this approach it returns results much faster than the find command, which only looks for files when you tell it to. Depending on your system, the locate command may need to be configured initially, or it may be pre-configured to work out of the box.

As its name implies, the Linux mkdir ("make directory") command lets you create new directories.

Creating a new directory in your current directory is very simple. In our first mkdir example, we'll show how to create a new directory named "dir1":

mkdir dir1

If you want to create several directories at one time you can use a mkdir command like this:

Linux head/tail FAQ: Can you share some examples of the Linux head and tail commands?

Sure. The Linux head and tail commands are very similar, so I've included them here together. The head command command prints lines from the beginning of a file (the head), and the tail command prints lines from the end of files. There's one very cool extra thing you can do with the tail command, and I'll show that in the tail example commands below.

The Linux cat command means "concatenate and print files". Usually all I use it for is to display a file's contents, like this command that displays the contents of a file named "lighten-images.sh":

Whew, getting all the images together for the Tame Swing sample applications is taking a little time and a lot of effort. I hadn't thought about how to organize it, and now that I have a better feel for what I want to do it's just a matter of time.

If you want to see the images of the running applications I do have them on a temporary page here. Please note that this page may change at any time.

Question: How do I convert a String to a double with Java?

Answer: Converting a String to a double requires that you first convert the String to a Double object, then convert the Double object to a double data type (Double is an object, while double is a primitive data type).

Here's the source code for an example Java program that performs this conversion:

Java file writing FAQ: How do I append text to the end of a text file in Java?

The short answer is that you should create a FileWriter instance with the append flag set to true, like this:

BufferedWriter bw = new BufferedWriter(new FileWriter("checkbook.dat", true));

The rest of this article explains this.

Java String/float FAQ: How do I convert a Java String to a float?

Converting a String to a float requires that you first convert the String to a Float object, then convert the Float object to a float data type (Float is an object, while float is a primitive data type).

An example of a simple program that performs this conversion is shown below:

Question: How do I convert a String to a long with Java?

Answer: The Long class includes a method named parseLong() that serves just this purpose. An example of a simple program that performs this conversion is shown below:

As I note here I just uploaded the Tame Swing examples to the web site. Please read that post for more information.

Digging through my Mac laptop, I just found the old Tame Swing files laying around. These examples are a little old now, but I think they are great examples of the power of the Java Swing framework. Since they are hard to find on the internet I've gathered them into a little collection here.

Currently I just have the Java source code files there, but give me a couple of days and I'll see what I can do to get some of the examples running, and maybe include some screen shots there as well.

 

The Linux find command is used to locate files and directories based on a wide variety of criteria. I'll try to cover the most common find examples here.

Basic find command examples

To find a file or directory named "foo" somewhere below your current directory use a find command like this:

find . -name foo

If the filename begins with "foo" but you can't remember the rest of it, you can use a wildcard character like this:

The Linux mv command lets you move one or more files or directories. Since it's very similar to the cp command, I'll move through this post quickly.

Basic Linux mv examples

To rename a file currently named "foo" to a new file named "bar" just type:

mv foo bar

Although it's called the Linux mv command, it's commonly used to rename files.

To move a file named "foo" to the /tmp directory type: