Searching Files

Searching and finding files on your computer is critically important. As our digital files become more numerous, it becomes harder to search and find the files you wish to locate. To help search and find files rapidly, I discussed the methods I use to name files in Part 1. The method that I outlined creates a highly searchable and future-proof system for data synthesis and retrieval. In Part 2, I will explain some basic workflows that I use to easily search and find files. This post is intended for people unfamiliar with Unix. The search methods I discuss below are applicable to any good workflow or file naming system, but are especially tailored to the file naming strategy I described in my file naming method in Part 1.

My file naming method has four descriptors—ID string, token, key, and file extension. All file names contain these four descriptors in a specific order. For example, a typical file might look like the following:

The file name illustration above indicates the file is something I created on April 12, 2011 at 4:13pm and shared externally that was a personal file relating to design and visuals. See Part 1 for a more thorough explanation of my file naming convention.

Naming files using the above syntax makes finding files extremely easy. There are two main tools I use to search and find files. Let’s take a closer look at these tools.

The Tools

Spotlight
Spotlight is probably the simplest method to search and find files for anyone using a Mac. Some people even think Spotlight was forged from the purest tears collected from Apple’s most prized unicorns. Many excellent tutorials and reviews have been written on how to use Spotlight.1 A simple way to find a file is to search Spotlight using one or more of the four descriptors used in my file naming method. For example, if you know the file you are looking for was created in April of 2011, simply type 201104 into Spotlight and all the files that contain this ID string will be listed. If you type name:201104 into Spotlight, only file names that contain the string 201104 will be displayed.
For more fine-grain control, additional operators can be used within Spotlight to constrain the search. I have highlighted several specialized search operators in the table below that are useful to quickly find files using my file naming method.
Spotlight can be even further customized by using Spotlight within the Finder.2 Here several search criteria can be implemented. For example, to find all files created in 2011 that are personal recorded writing HTML files and less than 1Mb is size, this Spotlight search is performed:

Spotlight Example Searches:

name:201104 —Files created in April, 2011

name:201104 AND name:R1 —Personal recorded files created in April, 2011

name:20110401 OR name:20110402 OR name:20110403 —Files created on April 1st, 2nd, and 3rd of 2011

Glob
Using Spotlight I can find 99.9% of the files I am looking on my computer. However, there is another additional tool that I sometimes use; that tool is glob. Glob can do many things that Spotlight cannot. Globbing can expand a non-specific file name containing wildcard characters into a specific file name. The glob tool facilitates sophisticated file name matching patterns to be used to find files. Let’s take a closer look at how to use glob.
Globbing is found in many scripting languages such as Perl, Python, and Ruby. For our purposes it is easiest to use glob within the Bash shell. To use glob in Bash, launch the Terminal application from the Applications folder on your Mac and use the change directory command to navigate to the directory where you store your files. In my case the commmand is cd documents/archive. Now you are ready to Glob. To show how globbing works compared to Spotlight, I’ve provided the same queries as in the above table below, but this time using Glob commands instead of the Spotlight. Simply enter a Glob command into Terminal and press enter to find the files you are looking for.

Glob Example Searches:

ls 201104* —Files created in April, 2011

ls 201104*R1* —Personal recorded files created in April, 2011

ls 2011040[1-3]* —Files created on April 1st, 2nd, and 3rd of 2011

So why use Glob when you can do the same thing in Spotlight? Glob can match complex strings with wildcards and other specialize search terms that Spotlight cannot. To demonstrate the power of Glob, imagine you were trying to find a file and all you could remember was:

the file was created sometime in 2002 or between years 2006 through 2008

you recall creating the file sometime in the spring of one of the above years

you are uncertain if you create the file or it was emailed to you from friend

you are not sure what value the second number token was given

the file was a .jpg image

you posted it on your personal Web site

To find the files that satisfy the above criteria just glob:

$ ls 200[26-8]0[3-6]*[rc]1.?*.jpg

On my system, only one file matches this Glob. Here is a screenshot of my terminal window:

An additional benefit of learning to use Glob on the command line is that a plethora of other commands become immediately available for file and data manipulation that use much of the same syntax. Although these additionally tools like Find, Grep, or Ack are extremely powerful for complex searching, bulk file renaming, and other advanced manipulations, an explanation of these tools work falls outside the context of this post.

I hope the above search methods and the importance of developing a unified file naming system for your digital files are obvious. Once you have developed a trusted file naming system you will never be unable to locate files again.

Houdahspot is a very interesting GUI-based file search tool that leverages Spotlight that can used to do a number of specialized searches. It is faster than Spotlight and can be invoked manually or with application Launchers such as LaunchBar. ↩