textutil: Convert between various text file formats
Converting text file formats is a black art. In the ancient days before OS X, back in the 1990s, Apple included a text conversion program with what was then called System or Mac OS. In OS X, that program was replaced by
textutil, which is even more useful because it can convert files with today's complex HTML, docs, and other formats.
To convert a file, just specify the
-convert option, the new file type, the path to the source file, and the path to the output file using the
The example below shows how to convert a Microsoft Word file into HTML.
textutil figures out the source file type automatically. If you want to see what
textutil thinks your file's type is, use the
-info option, also shown below. Though
textutil isn't perfect, you gotta remember -- it's also not the 1990s.
To convert a Word document into HTML:
$ textutil -convert html MyWordFile -output /tmp/webfile.html
textutil's interpretation of a document's file format:
$ textutil -info MyWordFile
It might display:
Type: Word format
Size: 45568 bytes
Length: 4354 characters
Author: Mel Beckman
Last Editor: Mel Beckman
Created: 2012-07-08 09:11:00 -0700
Last Modified: 2012-09-13 11:52:00 -0700
Contents: Q. I have a question about wri...
top: Find the CPU hogs in your system
top command is familiar to Linux and Unix users. It lists the busiest programs running on a system, helping you determine why a system might be running slowly. Apple's graphical Activity Monitor application does the same, but
top gives you a quick look without leaving the command-line environment.
top displays the first 20 programs in its list. The problem is that, for some reason, OS X's
top sorts its list not in order of descending CPU usage but in order of descending process ID. To get the list in proper CPU usage order, add the
-o cpu) option, as shown below. The
top list also shows which programs are running and which are "sleeping" -- waiting for input/output operations to complete. When a system is slow,
top usually reveals the culprit.
uptime: Show the time since last reboot and how busy the system is
If you need to know how long it's been since a Mac rebooted,
uptime is the command for you. It shows the current time of day, plus the elapsed time since last reboot in days, hours, minutes, and seconds. For some reason, Windows doesn't have this command, but it probably isn't up long enough to matter.
uptime shows the number of users logged in and the load averages (the number of processes waiting to run) of the system over the last one, five, and 15 minutes. What values are good or bad for load average depend on the number of CPUs available. A load average of 4 isn't bad for a quad-core Mac, but it would indicate a very busy single-core system.
16:04 up 721 days, 15:37, 2 users, load averages: 0.72 0.81 0.81
These are the 20 OS X command-line utilities you can get the most value from. Now it's up to you to do so!
This story, "Top 20 OS X command-line secrets for power users," was originally published at InfoWorld.com. Follow the latest developments in Mac OS X at InfoWorld.com. For the latest developments in business technology news, follow InfoWorld.com on Twitter.