How To Save Linux Command Output To An Image Or A Text File

Save Linux Command Output To An Image Or A File

Have you ever been in a situation where you wanted to send the output of a Linux command to your colleague or friend to get help? This is simple Linux hack will definitely be useful to you. You can save a Linux command output to an image or a file and send it to the respective person who wants to review the output of a particular Linux command’s output. You don’t need to install any additional tools.  You need to install ImageMagick. This can be helpful if you need to send the output to a technical support person or a Linux administrator.

Save Linux Command Output To An Image

Install ImageMagick tool first. In Ubuntu-like systems, you can install it a shown below.

sudo apt-get install imagemagick

In Arch Linux and its derivatives, run:

sudo pacman -S imagemagick

Now, to save a output of any Linux command to an image, just run the following command:

ifconfig | convert label:@- myipaddress.png

The above command will save the ifconfig command output to an Image and save it in the current working directory. Let us bread down the above command and see what each option does.

  • ifconfig will display the IP address of your Linux system.
  • convert command will save the output to an Image.
  • label:@- myipaddress.png will save the command output to the image named myipaddress.png.

Here is the output of the above command in my Arch Linux.

Here is another one. I saved my Linux Kernel output to an Image.

uname -a | convert label:@- mylinuxkernel.png

Sample output:

What we have seen above is we have saved the command’s output in an Image. Also, we can save the output on an existing Image file. To do this, run:

convert -font -misc-fixed-*-*-*-*-*-*-*-*-*-*-*-* -fill black -draw "text 270,260 \" `ip addr` \"" Linux.jpg myipaddress.jpg

This command will print the output of “ip addr” command to an image called Linux.jpg and saves it with a new name “myipaddress.jpg”.

Here is the output of the above command:

Pretty easy, isn’t? You can save the output of any command and send it to anyone who can help you to fix your system.

Save Linux Command Output To A Text File

We know how to save a command’s output to/into a image. We can save the output of a Linux command to a file too.

For example, we can save the “ip addr” command’s output to a file called myipaddress.txt using command:

ip addr > myipaddress.txt

To verify it, view the text file using your favorite text viewers. Or, we can do using “cat” command like below.

cat myipaddress.txt

The following command will save my pacman.log to a file called mylogs.txt.

tail -f /var/log/pacman.log  > mylogs.txt

And, we can easily save the IP details using command:

ifconfig > mynetworkdetails.txt

You might wanted to write the output of a command to multiple files. Here is how to do it.

uname -a | tee file1 file2

The above command will write the output of “uname -a” command to file1 and file2. If the files doesn’t exist already, it will create them.

By default, it will overwrite the contents of file1 and file2. If you want to append the output to the existing contents, use -a flag like below.

ifconfig | tee -a file1 file2

This command will not overwrite the existing contents of file1 and file2. Instead, it will simply append the output of the ifconfig command to file1 and file2. In other words, these two files now have the outputs of “uname -a” and ifconfig” commands.

And, that’s all. You know now how to save any command’s output to an Image or a text file. Hope this helps. More good stuffs to come. Stay tuned!


You may also like...

4 Responses

  1. SonicEricsson says:

    very usable

  2. Peter Rasmussen says:

    It doesn’t work for me.
    I get:
    bash-4.3# uname -a | convert label:@- mylinuxkernel.png
    convert: not authorized `@-‘ @ error/property.c/InterpretImageProperties/3445.
    convert: no images defined `mylinuxkernel.png’ @ error/convert.c/ConvertImageCommand/3257.

  3. John Piers Cilliers says:

    Nice article. Just a quick one, perhaps I’m not following you correctly as regards “saving the command’s output in an Image”. I’m using ARCH and by default (I think) imagemagick [currently installed] is installed when you install ARCH. In any event it is installed and think it’s pretty neat but get this when I try to run the command. zsh: no matches found: -misc-fixed-*-*-*-*-*-*-*-*-*-*-*-*

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.