Save The Output Of Any Terminal Command With One Parameter

Windows/Mac/Linux: The command line is an extremely useful tool. If you have a command that returns a wall of text, you can save it to a single text file with this simple parameter.

By using a single parameter at the end of your normal commands, you can pipe the output directly into a basic text file. Just add > FILENAME.txt to the very end of your command. This will create a .txt file with everything you would have seen on the screen in an easy-to-copy form. So, if you wanted a list of all the files in your Movies directory, you would run the dir command with this parameter (for Windows users):

CD C:UsersmeMovies
dir > mymovies.txt

Open up mymovies.txt, and you'll see a list of every file in that Movies folder.

If you want to put the file somewhere other than your working directory, you can spell out the location in it's entirety. For example:

dir > C:UsersJimmyJoUserManDocumentsheywhatsinhere.txt

Many of you command-line veterans are very familiar with this trick, but for those still learning their way around, it's a great shortcut to have on hand.

How to copy command prompt outputs to the Windows Clipboard [Ghacks]


    ... Why do your paths have no slashes? Generally speaking just for day to day use, this is far less useful than this post would suggest.. Why save it to a file then open the file in a text editor, when you can pipe it into something that will allow you to work with the data quicker and more efficiently. Windows comes with More for basic line by line viewing - for more advanced console users I recommend the GnuWin32 packages available below, or the ever popular cygwin - both of which have equivilents of unix 'less':

    Output redirection is really more for storing for processing computationally.

    Also.. Please put more articles about PowerShell.. I'm entirely oblivious to how you guys can keep posting articles about how to use the regular windows command line, when PowerShell comes with heaps of power built right in (more inbuilt functionality than even unix, and highly extensible), and is standard on all windows installs from Windows 7 onwards..

    It just makes you look outdated.

    Last edited 12/06/13 1:07 am

    Tee is often more useful for capturing output to a file. It's not part of the DOS command prompt, but it is part of Windows PowerShell and Mac/Linux. Tee outputs information to a file and the screen at the same time. Try:

    $ echo 'hello' | tee hello.txt
    $ cat hello.txt

Join the discussion!

Trending Stories Right Now