If you’re doing work at the command line on your Windows box, it’s sometimes useful to copy the output of a command to the clipboard, but who wants to try and scroll and click to use copy and paste? Here’s how to do it the easy way.

Note: For the purposes of our exercise, we’ll be using the built-in clip utility in Windows 7 or Vista—if you are using Windows XP, you can download clip.exe from Microsoft, just make sure to save the file in the Windows directory.

Copy Output from Command Line Applications to the Clipboard

To copy text from a command to the clipboard, we’ll just pipe it into the clip command, like this:

<command> | clip

For example, if you wanted to output from the echo command into the clipboard, you could do this:

You can also use redirection to send a text file directly into the clip utility, like this:

clip < filename.txt

In this example I’m gonna put the contents of the single.php file onto the clipboard:

Of course, you could also use the type command and then pipe it to the clipboard like so:

Regardless of the one you use, you’ll then be able to paste the content into any other application that you’d like:

Create a Context Menu Helper to Copy File Contents to the Clipboard

You can take the clip utility a step further by adding a context menu item that lets you copy the contents of any file directly to the clipboard. All you’ll need to do is follow the instructions in the following article, or download the reghack file.

Create a Context Menu Item to Copy a Text File To the Clipboard in Windows 7 / Vista / XP

And of course, don’t forget that you can always copy the path of the file to the clipboard through the context menu.

Profile Photo for Lowell Heddings Lowell Heddings
Lowell is the founder and CEO of How-To Geek. He’s been running the show since creating the site back in 2006. Over the last decade, Lowell has personally written more than 1000 articles which have been viewed by over 250 million people. Prior to starting How-To Geek, Lowell spent 15 years working in IT doing consulting, cybersecurity, database management, and programming work.
Read Full Bio »