How To Save Linux Command Output To An Image Or A Text 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. All you need to have is only 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
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!
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Facebook | Twitter | Google Plus | LinkedIn | RSS feeds
Have a Good day!!