Command Line usability basics: Redirection
March 29th, 2007 - Command Line, How to, Mac OS X, Tips & Tricks
Mac OS X is so user friendly that many Mac users probably don’t know they’re sitting on top of a powerful Unix base, accessible by the Terminal app. Our feeling is that since the command line is there, you should be able to use it to some extent. In our continued quest to propagate OS X command line knowledge, we bring you some information on the extremely useful redirect utilities. Redirects allow you to take the output of certain commands and create new files or add to existing ones with this data, very useful indeed.
| Command | Usage |
| command > newfile | Redirects the output of the command to newfile |
| command >> existingfile | Appends the output of the command to the end of existingfile |
Examples of redirects in use:
If you wanted to create a text file with data from the ps command, but controlled only for Dashboard related processes running, this is what you would type at the command line:
ps -aux | grep Dashboard > dashboarddata.txt
If you wanted to add at the end of the file we just created, dashboarddata.txt a list of Widgets you have installed, you would type the following:
ls -l /Library/Widgets >> dashboarddata.txt
The uses for redirection are endless and you’ll find that the more time you spend in the command line, the more you’ll want to use redirect for aiding certain tasks.
Posted by: Editor

Order Mac OS X 10.6 Snow Leopard today from Amazon.com - $25!

Write a comment