Manipulate text files in various formats, textutil first appeared in OS X 10.4
Syntax textutil -info [options] file ... textutil -convert fmt [options] file ... textutil -cat fmt [options] file ... textutil -help [options] file ... Key -help Show the usage information and exit. -info Display information about the specified files. -convert fmt Convert the files to format fmt and write each one back to the file system. -cat fmt Read the specified files, concatenate them, and write the result out as a single file in the indicated format. fmt One of: txt, html, rtf, rtfd, doc, wordml, or webarchive -extension ext Specify an extension to be used for output files (by default, the extension will be determined from the format). -output path The file name to be used for the first output file. -stdout Send the first output file to stdout. -encoding IANA_name | NSStringEncoding The encoding to be used for plain text or HTML output (by default, the output encoding will be UTF-8). -inputencoding IANA_name | NSStringEncoding Force all plain text input files to be interpreted using the specified encoding (by default, a file's encoding will be determined from its BOM). -format fmt Force all input files to be interpreted using the indicated cated format (by default, a file's format will be determined mined from its contents). -font font The font to be used when converting to rich text. -fontsize size Font size (in points) to be used for converting plain to rich text. -- Specify that all further arguments are file names. Additional options for HTML and WebArchive files: -noload Do not load subsidiary resources. -nostore Do not write out subsidiary resources. -baseurl url Specify a base URL to be used for relative URLs. -timeout t Specify the time in seconds to wait for resources to load. -textsizemultiplier x Specify a numeric factor by which to multiply font sizes. -excludedelements (tag1, tag2, ...) Specify which HTML elements should not be used in generated ated HTML (the list should be a single argument, and so will usually need to be quoted in a shell context). -prefixspaces n Specify the number of spaces by which to indent nested elements in generated HTML (default is 2). Additional options for treating metadata: -strip Do not copy metadata from input files to output files. -title val Specify the title metadata attribute for output files. -author val Specify the author metadata attribute for output files. -subject val Specify the subject metadata attribute for output files. -keywords (val1, val2, ...) Specify the keywords metadata attribute for output files (the list should be a single argument, and so will usually need to be quoted in a shell context). -comment val Specify the comment metadata attribute for output files. -editor val Specify the editor metadata attribute for output files. -company val Specify the company metadata attribute for output files. -creationtime yyyy-mm-ddThh:mm:ssZ Specify the creation time metadata attribute for output files. -modificationtime yyyy-mm-ddThh:mm:ssZ Specify the modification time metadata attribute for output files.
Examples:
Display information about foo.rtf.
$ textutil -info foo.rtf
Convert foo.rtf into foo.html.
$ textutil -convert html foo.rtf
Convert foo.txt into foo.rtf, using Times 10 for the font.
$ textutil -convert rtf -font Times -fontsize 10 foo.txt
Load all RTF files in the current directory, concatenate their contents,
and write the result out as index.html with the HTML title set to
Several Files".
$ textutil -cat html -title "Several Files" -output index.html *.rtf
Create a .txt file for each .doc file in the directory.
$ textutil -convert txt *.doc
Notes:
The textutil command exits 0 on success, and 1 on failure.
Some options may require a connection to the window server.
“A lot of people are afraid to say what they want, that's why a lot of people don't get what they want” ~ Madonna
Related macOS commands:
GetFileInfo - Get attributes of HFS+ files
pr - Convert text files for printing
say - Convert text to audible speech
setfile - Set attributes of HFS+ files
sips - Scriptable image processing system