I had to write a backup script the other day and used the find command to find the files that were older than a given amount of days.

DAYS_TO_KEEP=7
find /path/to/files* -type f -name *.bak -mtime $DAYS_TO_KEEP -exec rm {} ;

The -name argument uses the escaped asterisk so command completion does not replace it with all the file names.

The -mtime argument takes a number that is the number of days to look at.

The -exec argument takes a command and the {} is replaced with the current file name and the ; is the end of the command.

This is a small part of the power of the find command.

Windows 7: Create Library

digg del.icio.us TRACK TOP
By Eric Downing | Filed in Uncategorized | No comments yet.

Windows 7 has introduced the concept of a Libary. This is a folder that can contain other folders and is available in the Windows Explorer. So you may have decided that the 4 defaults folders aren’t enough:

  • Documents
  • Music
  • Pictures
  • Video

So to create a new library:

  1. Select : Start menu->All Programs->Accessories->Windows Explorer
    or
    Press + e
    and click on the Libraries folder in the left hand column.
  2. Right click in an empty space on the folder view and select New->Library
  3. Then name your Library
  4. Right-click your new library and select properties.
  5. Select Folders to include in your library.

Each library can contain multiple folders. Now everytime you open the explorer your library will be available to you and you do not have to dig into your file hierarchy to find your most used files.

Suggested Applications:

  • Work folders
  • Project folder

Windows: Grep for windows

digg del.icio.us TRACK TOP
By Eric Downing | Filed in Software, Utilities, Windows | No comments yet.

If you don’t have access to a Unix environment on your windows box, you can still search files with findstr. The findstr command will allow you to search files close to the same way as grep.

findstr /S "search string"

will recursively find your string in the current directory and subdirectories.

There are more options that you can find if you run the following command:

findstr /?

will show you the help message.

Tags: ,

Linux: watch command

digg del.icio.us TRACK TOP
By Eric Downing | Filed in Linux, Scripting, Utilities | No comments yet.

So every once in a while I want to see the progress of an upload or backup. So I turn to the watch command in Linux. The watch command gives the user the ability to re-run a command and see the updated output.

The syntax is ‘watch -n -d .

So for watching a file downloads progress you could run the following:

watch -n 30 ls -l filedownloading

This would show the ls output and you could watch the size of the file grow as it is dowload progress.

Ant unable to find tools.jar

digg del.icio.us TRACK TOP
By Eric Downing | Filed in Java, Programming, Utilities | No comments yet.

When attempting to run ant I get the following message: “Unable to locate tools.jar. Expected to find it in C:Program Files (x86)Javajre6libtools.jar”

This had to do with my JAVA_HOME not pointing to a Java JDK.

So if you download a JDK and update your JAVA_HOME environment variable to point to that directory, ant should run happily.

In BASH:
export JAVA_HOME=/path/to/jdk

IN DOS:
set JAVA_HOME=c:PATHtojdk

Tags: ,

Sample Ant file

digg del.icio.us TRACK TOP
By Eric Downing | Filed in Programming, Utilities | No comments yet.

Every once in awhile I go back and try to figure out how to create a basic ant build.xml file. So I am just placing a sample build.xml here.

The directory structure should be something like
./build.xml
./src/HelloWorld.java

The targets will create the build directory and compile the source and run a test execution of the class.

<project name="HelloWorld" basedir="." default="main">
<target name="clean">
<delete dir="build"/>
</target>

<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="src" destdir="build/classes"/>
</target>

<target name="jar" depends="compile">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="HelloWorld"/>
</manifest>
</jar>
</target>

<target name="run" depends="jar">
<java jar="build/jar/HelloWorld.jar" fork="true" />
</target>

<target name="main" depends="clean,run"/>

</project>

Tags:

I had recently reinstalled my system and was trying to run a simple class that consisted
of a “Hello World” program in Java. I received the following:

Compile:

$> javac LottoMain.java

Run:

$> java LottoMain

Exception in thread “main” java.lang.NoClassDefFoundError: LottoMain
Caused by: java.lang.ClassNotFoundException: LottoMain
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
Could not find the main class: LottoMain. Program will exit.

The compile line completed without errrors and the LottoMain.class file was there, but
what I didn’t know was that I no longer had the current directory “.” in my CLASSPATH variable.

After adding “.” to my CLASSPATH variable the run command gave me what I was expecting.

Run:

$> java LottoMain

Hello Eric!

Updating the CLASSPATH variable in Bash:
in my home directory/.bashrc file

export CLASSPATH=$CLASSPATH:.

Tags: ,

Java: Great link to Swing Examples

digg del.icio.us TRACK TOP
By Eric Downing | Filed in Java, Programming | One comment

Starting on my road to creating a Java based GUI I stumbled upon the following link within the “Creating a GUI with JFC/Swing” Train in the Java Tutorials from Oracle.

Using Swing Components: Examples

It has code examples and can really get you started on the road to a Java GUI interface.

Tags: , ,

Java: Creating a Window

digg del.icio.us TRACK TOP
By Eric Downing | Filed in Java, Programming | No comments yet.

This is the First of some basic articles about creating a GUI in Java. The following code is the basis of the following series of articles. I am using the Java Swing window toolkit.

import java.awt.*;
import java.swing.*;

class FirstWindow 
{

  public static void main(String[] args)
  {
      //Create Window object and set title bar text
      JFrame frame = new frame("First Window");

      // Set the Default operation when you close the window
      // This exits the program on closing the window
      // The default behavior is to HIDE_ON_CLOSE
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      // Now we need to Display the window
      // The null argument will place the element in the center of the screen.
      frame.setLocationRelativeTo(null);
      frame.pack();
      frame.setVisible(true);
   }
}

This is enough to display a simple window, but it will probably not have any useful size associated with it and it does not do anything.

The next step will be to add some useful widgets and eventually functionality to make the window useful.

Helpful info:
Java: Great link to Swing Examples

Tags: ,

Android: SD card unmounting when I connect to the computer

digg del.icio.us TRACK TOP
By Eric Downing | Filed in Android | No comments yet.

So I was charging my Droid X and noticed that while I was connected I could not use my SD card anymore. And the camera will not take any picutures if there is no SD card present.

So I pulled down the task bar and selected “USB connection” .

Once I selected the “Charge Only” option, it was smooth sailing and my SD card was available to my phone again.

This is also the place to turn on “USB Mass storage” when you are ready to copy off those pictures.

Tags: