printing a directory list

One thing that OS X is lacking that I used all of the time in OS 9 is the print window command in the finder. There are a few ways to get around this limitation. One way is to open the window you want a print out of. Grab the icon at the top middle of the window and drag it onto the printer icon. This will print a list in alphabetical order of the contents. Sometimes this is what you want. But if you want the list in another order you may need to use your terminal to pipe a ls command into an application that you can print with, or to lpr. You can pipe the ls into a sort, grep or awk to arrange the list and grab the elements you want first.

Here is an example of piping a list of /etc into bbedit using grep to grab all files with .rc on the end, and awk to grap the file names and the modification dates.

ls -l | grep \.rc | awk ‘{print $6, $7, $8, $9}’ | bbedit

the result is:

20 Sep 2003 efax.rc
12 Sep 2003 mail.rc

BBEdit comes with a command line utility that allows you to pipe into it. Then I can print from BBEdit my list. The other advantage of this is that you can then copy the list and paste it into an email message if you have to email a list to somebody. One shortcoming, is that you can’t really sort by kind, unless you have an extension on the file name to distinguish it.

Awk uses white space delimiters to read into it’s numeric variables. If you want to rearrange the copy so the modification date is after the file name do this:

ls -l | grep \.rc | awk ‘{print $9, $6, $7, $8}’ | bbedit

now you will get this result:

efax.rc 20 Sep 2003
mail.rc 12 Sep 2003

if you want to print directly to your printer pipe it into lpr rather than bbedit:

ls -l | grep \.rc | awk ‘{print $9, $6, $7, $8}’ | lpr

Leave a Reply

You must be logged in to post a comment.