Thursday, May 28, 2009

Save Output Of A Command Entered In Ubuntu Terminal To A File

Here's a small tip which would help you save the output of a command entered in Ubuntu to a file. This can be very useful if you would like to keep a copy of it to a file, or send it to your friend etc.This can be also useful for automation scripts to save outputs as logs. So here's how you do it :

In this example, I would like to save the output of ifconfig to a file called debug.txt. So in the terminal I have to type ifconfig > debug.txt . This will save the output to debug.txt which will be located in your home folder . If you want it to be on your Desktop , then just enter the full location to your desktop, example : ifconfig > /home/username/Desktop/debug.txt


  1. IF you want to see the output on the terminal as well, use tee as follows:

    ifconfig | tee /home/username/Desktop/debug.txt

    Beware! if the file debug.txt already exists, it will be overwritten. To avoid that, use the append option, tee -a as follows:

    ifconfig | tee -a /home/username/Desktop/debug.txt

  2. Thanks Sadanand! I've seen just about everyone use the > method and was looking for a way to be able to view the output as well. Especially useful with the server distros where only one terminal instance is used.

  3. Thank you very much! I was looking something that would let you see the output in the terminal AND output it to a file. This is greatly appreciated and very helpful!


Note: Only a member of this blog may post a comment.

Related Content

Related Posts with Thumbnails