Mac OSX Terminal: Copy Window Contents

08
2014-07
  • Adam_G

    I am running a java script, which has some text output. I'd like to copy/paste that output. If I do ⌘-A, it copies everything that's been typed that session, even if I typed clear beforehand. How can I copy only what is currently displayed?

  • Answers
  • shub

    echo 'sup3ru53r' | pbcopy

    • Select the text and copy (⌘ cmd+C)
  • Nevin Williams

    Without modifying your code, you can...:

    • Set the number of buffered lines equal to your screen size, in Terminal Preferences. It can be found under the Settings tab, and then the Windows button.
    • Clear the scrollback buffer with cmd-K immediately before running your script, then use cmd-A C as normal.

  • Related Question

    osx - Web page from the terminal
  • juanpablo

    I use Snow Leopard. How I can send a html page to a web browser from Terminal.app?

    If I am in $HOME dir, with a file myPage.html, can I view this file in a browser right from Terminal.app?


  • Related Answers
  • Arko

    Yes, to open a file from the Mac OS X terminal you can use the open command. This is the same as double-clicking on the file to open it.

    You can specify the application to use for opening the file with the -a option. If not specified, the default application set via LaunchServices is used to open the file (1).

    In your case, to open a HTML file with a browser from the terminal, use this command:

    $ open -a /Applications/YourBrowser.app YourFile.html
    

    Or, you can omit the-a option...

    $ open YourFile.html
    

    ...to open it with the default browser. (2)


    1) : Usually this is the application that was used to create the file. You can change this via the "Get info..." window. (Select the file, then hit CMD + I.)

    2) : Be aware that this method may not work depending on the application set to open the file. This may be done for one or for all files. Typically, on a web developer computer, the application set to open HTML files will likely be a text or code editor.