5

I'm no expert on CLI or using the terminal or anything, but I like playing around with my computer.

When I create a .txt .html or .md file or whatever using the 'touch' command in terminal, they work fine. But .rtf file I create just give me the error

"The document “foo.rtf” could not be opened."

What am I doing wrong? Are you not able to create files in this manner?

1 Answer 1

13

As you've likely discovered, touching a nonexistent file will create a zero-byte file with the name you specify. (touch is also used to update the modification time on an existing file. See man touch for further details.)

The problem you're running into is that though a completely empty file is valid HTML, text, or Markdown, it is not valid RTF—this is true of many file formats, actually, which are structured in a particular way and require some data to be present be valid.

Based on my experimentation, the bare minimum RTF file appears to be

{\rtf1}

If you'd like to create a blank RTF file from the shell, try this:

echo '{\rtf1}' >Foo.rtf 

Note the above will overwrite Foo.rtf if it exists.

2
  • 1
    Thank you, @zigg. I really appreciate that you explain the reasoning behind this. If I may ask for my own understanding, what is happening with {\rtf1}? Is that setting some sort of data about the file?
    – Tomulent
    Commented Sep 11, 2013 at 0:30
  • 2
    I believe all RTF documents use it as the top-level construct. Try saving out an RTF document and using the cat command to dump it to the screen—every one I've seen starts with {\rtf1.
    – Mattie
    Commented Sep 11, 2013 at 1:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .