In years past there have been many times that I wanted to easily print a listing of the files in a given directory. For example, whenever I do a restore of any system, I would like to have a record of all the applications I had installed prior to reformatting. This is actually the main use I have for such an operation, but there are times when I need to print a file listing from a specific directory as well.
Lately I have been learning more of the INs and OUTs of the UNIX part of my OS X machines. I have little knowledge of some basic Shell commands and wanted to increase my knowledge of a better working knowledge of UNIX. I went out and purchased an excellent book, Mac OS X Unix 101 Byte-Sized Projects
. It is here that l learned a little trick known as a "pipeline".
For those of you that don't know what this is, it is basically a way of passing the output of one command to another. You can string these together collectively creating a pipeline. The name comes from the pipe character ( | ) which separates each command.
With that knowledge, I created a easy way to print out directories. On your Mac (I am sure it is similar on PC) open up your Terminal (Applications/Utilities/Terminal) and type in the following command:
ls /Applications | Mate
Breakdown:
- ls: the command to display the contents of a specified directory
- /Application: the directory to be listed
- | Mate (pipe Mate): The command that takes the output of ls /Applications and pipes it to TextMate. Mate could also be replaced with 'edit' if you have TextWrangler installed.
Once you do that, the appropriate application opens with the output inside and you can print the file from there.