filename

Mac backups - handling spaces in filenames with find, tar, and xargs

This morning I decided to take a few minutes to backup all the songs I've purchased over the last half-year. These are all on my Mac OS X system, under the Music folder in my home directory.

The problem with trying to do this with standard Unix tools is that all these subdirectories and filenames have spaces in their names. Just looking at the Music folder, it contains many directory names like this:

Linux find command: How to find files not matching a pattern

Unix/Linux find "patterns" FAQ: How do I find files or directories that don't match a specific pattern (files not matching a regex pattern, or filename pattern)?

In my case I just ran into a situation where I needed to find all files below the current subdirectory that are NOT named with the filename pattern *.html . Fortunately with the newer Unix/Linux find syntax this solution is pretty easy, you just include the -not argument, like this:

A Java FileFilter example

Summary: A Java FileFilter example, including a complete implementation of a Java FileFilter class.

I don't have much time for discussion today, but here's the source code for a Java FileFilter example I created in a text editor I wrote named "Jelly":

Java: How to list all files in a directory that match a filename extension

I just ran across this Java method I used to create a list of all files in a directory that match a specific filename pattern, or more specifically, matched the same filename extension.

The Java "list files in a directory" source code

First, here's the source code for this Java "list files" method. I'll follow this code with a brief description:

How to use multiple filename search patterns with Linux find

Linux find FAQ: How do I use the Linux find command to find multiple filename extensions (patterns) with one find command?

Problem

You want to use the Unix/Linux find command to search for multiple filename types (or patterns). You know you can run the find command several times, one for each filename extension you're looking for, but there must be a way to search for multiple filenames at one time.

Perl - How to process every file in a directory that matches a pattern

Perl FAQ: "How can I process every file in a directory that matches a certain filename pattern?"

There are several ways to do this, but I normally use the glob function, because I can remember the syntax pretty easily.

Let's look at a couple of glob examples.

Using the glob operator

You can use the glob operator to get a list of all files in the current directory like this:

A Perl temp file example

Many times in Perl applications you need to be able to create a temporary file (a Perl temp file). In this scenario you don't want to get into the system-specific details of temporary directories and things like that; you just want to create and use a temporary file.

Here are some Perl code snippets that should help get you started down this road.

Ruby “glob”: How to process each file in a directory that matches a certain pattern

Here's some sample Ruby source code that shows how to do something with every file in a directory, where you only work on filenames that match a pattern you're interested in. For example, in my case I'm only interested in processing files that end with the filename extension WMA, so this first snippet of Ruby code shows how to print out the name of each file in a directory with the WMA extension:

Use File::Basename to separate a filename from its directory

Question: Using Perl, if I have a string that includes the full path to a file (i.e., it includes both the full path of the directory and the filename), how do I split the string into its directory and filename components?

Answer: Use the basename and dirname methods of the Perl File::Basename module.

The following example shows how to break this string '/Users/al/work/file1.pdf' into its directory and filename components:

Batch rename filenames with this shell script

Here's a Unix shell script that converts all "*.png" files in the current directory to lower-case names. In my case I had files named "Slide1.png", etc., and I wanted them to be named "slide1.png", and this script did the trick.