Capturing text and images

Capturing text and images

 

This post was last updated on July 9th, 2020 at 04:31 pm

There are many ways to capture text or images and save them for later (such as for bug reports, etc):

  • Copy/Paste – 3rd mouse button
  • Highlighting with the mouse is the “copy” portion. Then use the 3rd mouse button to perform a paste (be sure to be in “insert mode” in your editor of choice when pasting. If your 3rd mouse button (both left and right pressed at the same time) doesn’t work, then you should enable it. You can often enable the 3rd mouse button in /etc/X11/XF86Config with

             Option      "Emulate3Buttons" "yes"
    
  • Copy/Paste – Paste menu item
  • Highlighting with the mosue is the “copy” part. Then you often have a “paste” menu item available so you can paste either in your editor or in your console menu (such as xterm or gnome-terminal).

  • CTRL+C/CTRP+V
  • Occasionally you will find where a CTRL+C, CTRL+V combination will perform a copy/paste, but this is probably rare.

  • Print Screen
  • Red Hat 8.0 is configured so that the “Print Screen” key will take a snapshot of the screen and then ask you for a filename to save it as. If you are on a V/K/M switch box that responds to the “Print Screen” key, just press “Print Screen” twice to pass the keystroke through.

  • Redirect Output
  • You can redirect stdout and stderr which can be saved to file, etc. Here is an example of the “output” operation which will overwrite the destination filename:

    ps ax > /tmp/ps_ax.txt

    Note that if /tmp/ps_ax.txt exists, it will be overwritten with the results of the above command.

    Here is an example of the “append” operation which will append to the existing file or will create a new file:

    ps ax >> /tmp/ps_ax.txt

    Note that if /tmp/ps_ax.txt exists, it will have the contents of the above command appended to the end of the file.

    I always test if a file exists by using the tab key (bash shell) to perform filename completion — read up on Bash’s file name completion (man bash).

    Also note that stderr is different from stdout. To capture stderr, you need to refer to it as 2 as follows (the 2 must appear directly in front of the greater than sign — no spaces):

    ./myprog 2> my_stderr.txt

  • virtual console
  • If you have items on one of the text consoles that you need (and you don’t have to scroll to see it) then you can capture it using virtual console:

    cat /dev/vcs1 > /tmp/vcs1.txt

  • script
  • If you have a lot of reproducible output to capture you can use “script” to capture it. Simply run the command “script” and you will be placed back at the shell prompt. Then recreate your output, and when done type “exit”. You will be presented with a message that your results have been stored in a file called “typescript”.

    Here are some sample ways:

    cat /dev/vcs1 >> results.txt
    setterm -dump n     (where n is the console you wish to dump – results are stored in screen.dump in current directory)
    script
    tee
    serial cable / minicom logging feature

    So if you already have the text on a text console (usually F1 thru F6) and you need to capture it, then use something like the following:
    cat /dev/vcs1 >> results.txt

    A similar method is “setterm -dump 1”

    Replace the number 1 (in both methods listed above) with the correct console you wish to capture (console F1 = /dev/vcs1, console F3 = /dev/vcs3, etc.)

    I’m afaid that information that has already scrolled up beyond the visible screen (usually 25 lines) is in the video buffer and so I don’t have a method to capture that text — you’ll have to regenerate the data and use another means to capture it.

    If you can generate the data you need to capture, then just send the output to a file:
    ./myprog >>results.txt
    ./myprog >>results.txt 2>>results_err.txt

    Or if you need to keep working on the data produced by your program, then use “tee” as follows:
    ./myprog | tee -a results.txt | _other_commands_you_have_to_keep_working_on_data

    Another method is to use “script” as follows:

    script
    ./myprog
    exit

    All data that is produced before you type the word exit will be captured into the filename typescript.

    Capturing graphics

    Capturing just one window in X-windows
    import results.jpg
    then just point and click the crosshairs provided on the window to capture.

    Capturing the entire X-Windows screen:
    import -window root results.jpg

    Or you can add a pause (so you can get ready first) with:
    import -pause 3 -window root results.jpg

    Of course you’ll have to count down yourself or here’s a couple of ways to let yourself know when the picture has already been taken.

    If you have sound, then you could do this:

    import -pause 3 -window root results.jpg; play done.wav

    If you don’t have sound, then just start something like xcalc:

    import -pause 3 -window root results.jpg; xcalc

    Then when you hear the sound or you see the calculator pop up you know that the image has already been captured — the pause gives you time to move your text box out of the way before the image is captured.

    Some collection tools:

    The Linux Trace Toolkit:-
    http://www.opersys.com/LTT/

    Compaq Survey Utility:-
    http://h18007.www1.hp.com/support/files/server/us/download/16241.htmL

    DMIdecode:-
    http://www.nongnu.org/dmidecode/

    For Redhat only:-
    http://www.ibiblio.org/shadow/sysreport/

    http://www.nongnu.org/dmidecode/

    http://ezix.sourceforge.net/software/lshw.html

    http://syseng.zko.dec.com/~seger/ – collect for linux

    Previous Rsync and Linux
    Next Cygwin
     

    About author

    Sibananda Sahu
    Sibananda Sahu 186 posts

    A Linux Kernel Developer and a Firmware Developer by profession. Have worked with few big companies: BROADCOM Corporation, Cypress Semiconductor, LSI Corporation, TOSHIBA Corporation, Western Digital; on various cutting edge technologies and product lines, such as: RAID storage Driver, SSD Firmware, WLAN Firmware etc. Having more than 9 years of experience in Software Engineering domain. Now, took a pledge to educate all aspirant students to teach about Linux Kernel Development.

    View all posts by this author →

    You might also like

    How To 0 Comments

    How To Install Apache Tomcat In Ubuntu 20.04 LTS?

    This post was last updated on August 1st, 2020 at 01:51 pmApache Tomcat or simply Tomcat is a web server and servlet container that is used to serve Java applications.

    How To 0 Comments

    How To Add a User During Kickstart

    This post was last updated on May 26th, 2020 at 10:37 pm Adding a user during kickstart: /usr/sbin/useradd username /usr/sbin/usermod -p ‘<encrypterd_password>’ <username> Making encrypted passwords: $ openssl passwd -1

    How To 0 Comments

    How To Assemble Files With Cat Command In Linux/Unix?

    This post was last updated on August 1st, 2020 at 12:38 pmLinux or Unix provides cat command that can be used to create, view, and concatenate files. It reads the

    0 Comments

    No Comments Yet!

    You can be first to comment this post!

    Leave a Reply