I see a nicely colored output in my terminal.

The terminal has a "Export Text As" command but it saves a plain-text file without the colors. Same with copy&paste.

Do you know a way to save terminal output including colors?

  • If this is important to you, please let Apple know via apple.com/feedback/macosx.html (Applications/Utilities feedback area) or developer.apple.com/bugreporter (requires registering for a free developer account).
    – Chris Page
    Mar 10, 2012 at 21:42
  • Terminal now has a list of options for the basic Cmd-c copy command under Edit -> Copy Special, where you can toggle between Plain Text and rich text options. Nov 7, 2018 at 17:53

7 Answers 7


It appears that if you select text in the Terminal, then copy it, then paste it into an application that supports rich text (e.g. Mail, TextEdit, Word), then the text color will be preserved.

It appears that in Mail and TextEdit, the background color of the terminal is also pasted; in Word, it is not. I'm not sure how to explain this discrepancy.

  • What version of OS X are you using? This doesn't work on 10.7.4.
    – Wildcard
    Mar 18, 2016 at 0:45
  • 1
    @Wildcard It works for me on 10.11.3. I don't remember which version I was using when I wrote this
    – Max Nanasy
    Mar 18, 2016 at 0:48
  • 1
    I had trouble using regular Copy to paste into Mail — the colors were lost — but it worked when I used Edit -> Copy Special -> Copy Without Background Color (which I preferred anyway). It even worked with option-drag to create a rectangular selection. (10.12.6) Sep 6, 2017 at 19:58
  • Pasting into TextEdit worked great for me. Also if your email client has html formatting turned on, pasting into there should work as well.
    – Cole
    Aug 30, 2023 at 8:08

Amazing how posting a question boosts ones creativity.

I can open "Print" dialog and save to PDF and then copy colored output from the PDF.

Also iTerm2 terminal app has a shortcut CMDOPTC that copies with formatting.

  • 1
    This solution is perfect for maintaining colored output when creating terminal examples in a Keynote presentation. Thx!
    – beausmith
    Sep 19, 2011 at 1:25
  • 1
    @Wojtek: You're welcome, even though it cost me a little reputation when you unaccepted my answer... ;-)
    – martineau
    Mar 6, 2012 at 19:36
  • +1 for the iTerm2 shortcut! Why is that not even in the meny??? Jan 30, 2017 at 5:42
  • 1
    That ... is definitely the most useful find since a long time!!!
    – emvee
    Nov 3, 2017 at 12:56
  • 2
    If you ⌘ + ⌥ + C from iTerm2, open Keynote, and paste it, it will import it as table data. I haven't quite figured out how to format the data in a useful way, but there's potential there. Sep 14, 2018 at 14:24

you can try to paste the colored output to the clipboard like this:

% command_which_produces_colors | pbcopy -prefer rtf

which puts some rtf (possibly colored and formated) stuff into the pasteboard of macos. you can then use any other that understands richtext to access the clipboard.

this is obviously not the same as "select it with the mouse" but maybe worth a shot.

  • Doesn't seme to work. First problem is that command_which_produces_colors notices it doesn't print to the console so it skips the colors. I can force some of them to print colors anyway, so following command outputs colors to the terminal: CLICOLOR=1 CLICOLOR_FORCE=1 ls -alh | tee But pbcopy copies no colors: CLICOLOR=1 CLICOLOR_FORCE=1 ls -alh | pbcopy -prefer rtf +1 for pbcopy/pbpaste commands. It's great for copying long files to clipboard: "pbcopy < longfile.txt" Jan 13, 2011 at 7:46
  • 3
    When I try this, if command_which_produces_colors produces ANSI codes, then pbcopy -Prefer rtf just copies the text including the ANSI codes (e.g. it copies [0;34mText for blue Text). It seems as though converting the ANSI codes to RTF may be required as an intermediate step.
    – Max Nanasy
    Jan 8, 2015 at 2:13

Based on @akira's answer, I came up with the following:

  1. Download the source package for ansifilter (can also be installed by brew install ansifilter)
  2. Follow the instructions under INSTALL to build and install ansifilter
  3. Run <command that produces colors> | ansifilter --rtf | pbcopy -Prefer rtf
    • You may need to pass arguments to <command that produces colors> to force it to produce colors even though its output is piped, e.g. ls --color=always instead of just ls
  4. You can then paste into an application that supports rich text (e.g. Mail, TextEdit, Word)

OS X has several keyboard shortcuts (hotkeys) for copying the screen. These will save your screenshots as a jpg files on the desktop. Here's a list of them:

Cmd-Shift-3                             Take snapshot of the whole screen
Cmd-Shift-4                             Take snapshot of the selected area
Cmd-Shift-4-Spacebar                    Take picture of a window
Escape                                  Cancel
Hold Spacebar after Drawing the region  Move the selected area
Hold Option                             Resize selected area
Hold Shift                              Resize selected area horizontally 
                                        or vertically 

There's also a "Grab" application located in the Applications | Utilities folder that does the same job, plus has a few extra features such as delay.


In Snow Leopard (10.6.8) the default screenshot format is png not jpg, although that can be changed to any one of many others -- including pdf -- using the free 3rd-party TinkerTool preference settings utility.

  • 9
    a .jpg is kind of not as nice as "pure" text.
    – akira
    Jan 4, 2011 at 18:23
  • 3
    +1 for the lesser known shortcuts for selection area.
    – Daniel Beck
    Jan 4, 2011 at 19:05
  • @akira: The OP wants colors -- something you can't do in a plain-text format unless you count embedded ANSI escape sequences -- and those would need something to interpret them like a terminal emulator, but then you're back to the original problem.
    – martineau
    Jan 4, 2011 at 21:11
  • 2
    @martineau: depending on the capabilities of the clipboard colors are saved by markup (eg, richtext or html) when you copy from a browser or from word or from xyz. and, depending on the application that receives such marked up snippets they can show the colors AND the text quite ok. the terminal receives ascii escape sequences, correct, but just because it receives ascii escape sequences does not mean it has to a) store them (eg, think html-terminal) b) it can enhance the selected text a lot of ways (you can put different mime-types at a good clipboard at once).
    – akira
    Jan 4, 2011 at 21:48
  • 3
    @akira A JPG is a really poor choice of image format for something like a screenshot. Large areas of single color and sharp single pixel lines etc. all over it. Fortunately, Apple are not that silly and the file it saves is a PNG. lbrandy.com/blog/2008/10/my-first-and-last-webcomic
    – rjmunro
    Mar 1, 2012 at 11:09

The way I do this is via the excellent Textmate 2 app.

  1. Copy from R graphical window
  2. Paste into an empty textmate document
  3. Change document type to R Console or R as preferred
  4. Use the copy-with-style tmbundle (shift-cmd-c)
  5. Paste into mail app compose window

I have to say it would nice if shift-cmd-c worked directly in the R console window.


In iTerm2 you can go to EditCopy with Control Sequences to copy with the ANSI colour codes.

Then you just need something that will render ANSI colours.

You must log in to answer this question.

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