Get terminal contents [duplicate] - linux

This question already has an answer here:
Read screen character from terminal
(1 answer)
Closed 2 years ago.
Is it possible to get a snapshot of the text contents of a Linux terminal?
Both tput and terminfo support "cup" mode (e.g. tput smcup to start alternate buffer mode) which implies they must save the screen state somewhere. Is it possible to get these contents?

You can save a snapshot of the text contents of a Linux terminal to
a file using GNU Screen
hardcopy
feature but only if you started screen beforehand. Apart from that,
you can restore terminal contents saved with tput smcup using
tput rmcup but this works only in xterm (not only in xterm
terminal emulator itself but also in other terminal emulators
providing that $TERM is set to xterm. It doesn't work in Linux TTY
though).

Four Methods to Take Screenshot Capture in Ubuntu Linux
Use Print Screen
This is the most common method to take screenshots. Pressing the “Print Screen” button will take the screenshot of the “Entire Visible Screen”.
When we want to take a particular window, we can use “Alt+Print Screen”. Alt+PrintScreen will take only the particular window which is currently active.
Use gnome-screenshot
gnome-screenshot utility is part of the GNOME Desktop Environment, which can also be used to take screenshot. It also has a command line mode (gnome-screenshot)
From the command-line, just type the command “gnome-screenshot” to do the same. The command will take a screenshot and provide a dialog to save it.
$ gnome-screenshot
Capture Only the Current Window:
From the UI, to take the screenshot of the current active window alone, select “Grab the Current Window” and click “Take Screenshot”.
From the command-line, use the -w option as follows to do the same.
$ gnome-screenshot -w
Take Screenshot After Some Delay:
From the UI, you can also set a delay before taking the screenshots. Set the “Grab after a delay” to the required number of seconds. This will be really helpful when we need to take screen shots of navigation.
From the command-line, use -d option to do the same. -d 2 is used for delaying the screenshot for 2 seconds. So within the 2 seconds, we can make the window which we want to take screenshot as active.
$ gnome-screenshot -w -d 2
Capture a Particular Area:
From the UI, if you want to take a particular rectangle area alone, then select “Grab a Particular area” and click “Take Screenshot”.
From the command-line, use the -a option to do the same. Once this command is entered, the mouse pointer will be changed, and you can drag and select which area to take screenshot.
$ gnome-screenshot -a
Take Screenshot Including or Excluding Window Border:
From the UI, you can also include or exclude the window border by selecting/deselecting “Include the Window Border” option.
Use ImageMagic’s Import Command
ImageMagick is an open source software suite for displaying, converting, and editing raster image files. It comes with various command line tools, and one of that is “import”. Now we will see, how we can use import to take screenshots. You can install it by using apt-get on debian/ubuntu as follows:
apt-get install imagemagick
Capture Entire Screen using -window root option
Use the “-window root” option to take screenshot of the complete screen. The screenshot will be saved in the file name provided in the command line.
$ import -window root Pictures/Image5.png
ImageMagick supports more that 100 file types. You can use any one of them to store the output.
Use GIMP
You can also take screenshot from gimp. Launch gimp, and click “File->Create->Screenshot”. A new dialog window will open with options similar to gnome-screenshot.

Related

How can I enter text into Launchy and append it to the end of a text file?

I'm a Debian Stretch user coming from Windows. In Windows with the launchy app (also available for Linux), I had a method of entering text into launchy that was then appended to the end of a .txt or .md file.
To do this in Windows, I created a file called note.bat that contained the following:
echo %*>>"C:\collectednotes.md"
I'd make launchy aware of note.bat by adding its containing folder to “Launchy” → “Settings” → “Catalog” and adding filetype *.bat.
From there, I'd launch launchy, type note, hit Tab, enter some text, hit Enter, and then the text would be added to the end of collectednotes.md.
A mostly working process is detailed in my answer below. I'll give the green checkmark answer to anyone that can adjust this process (via note.sh and/or launchy plugin setup detailed below) to appropriately handle all special characters.
This may contain the solution to this question:
Which characters need to be escaped in Bash? How do we know it?
Solved (almost). I'm keeping this question unanswered and will give to whoever completes the remaining ~5%. Steps to get the 95% solution with xfce4-terminal version 0.8.3-1:
Install launchy and launchy-plugins (both are version 2.5-4 for me):
apt-get install launchy
apt-get install launchy-plugins
Open terminal to default location of ~/ and create collectednotes.md:
echo "# Launchy Notes Collected Here" > collectednotes.md
Create note.sh shell script:
echo '#!/bin/sh' > note.sh
Create shell script line 2:
echo ALL_ARGUMENTS='"$#"' >> note.sh
Create shell script line 3:
echo 'echo "$ALL_ARGUMENTS" >> ~/collectednotes.md' >> note.sh
If you open note.sh, it will look like:
#!/bin/sh
ALL_ARGUMENTS="$#"
echo "$ALL_ARGUMENTS" >> ~/collectednotes.md
Make note.sh executable:
chmod +x note.sh
Launch launchy and click the gear icon in upper right for settings. If consistency with launchy for Windows is desired, set launchy Hotkey to Alt+Space. If you receive a keyboard shortcut conflict message as I do on Debian with Xfce, first go to Settings, Window Manager, Keyboard tab, and clear Alt+Space as the shortcut for Window operations menu.
Next in launchy settings, go to Plugins tab and enable the plugin Runner. Click the + button and create a new Runner custom command as follows:
- Name: note
- Program: /home/YOURUSERNAMEHERE/note.sh (launchy does not like Program path of ~/note.sh, so a specific path with username is required)
- Arguments: '$$'
Click the Catalog tab and hit Rescan Catalog just in case. Hit OK to close launchy settings.
Now let's test it.
- launch launchy with Alt+Space or your hotkey
- type note (You may have to wait 10 second or so on first run. You'll know things are as expected when you see the text "note" with a orange/yellow icon containing silhouette of a person.)
- hit Tab
- enter some text (no need for single or double quotes or escapes), e.g.: Remember to donate at least $3 to Josh at Launchy https://www.launchy.net/donate.php
- hit Enter
Now open collectednotes.md to confirm the text was captured.
The remaining issues seem to be dealing with single quotes and double quotes. For example, consider the following note:
I don't know what I'd do without Launchy.
Which results in the following in collectednotes.md:
I dont know what Id do without Launchy.
Or:
Would David Allen like universal text capture from anywhere in Linux? My bet is "yes!"
Results in the following in collectednotes.md:
Would David Allen like universal text capture from anywhere in Linux? My bet is \yes!\
Single quoting and/or double quoting the input to launchy doesn't solve it. Note the launchy Runner custom plugin construction component of '$$' is a piece of this puzzle.
I'll give the answer to anyone that can adjust this process (via note.sh and/or launchy plugin setup) to appropriately handle all special characters. Maybe this would add proper escapes to user input with something like gsub.
The rationale for being exacting regarding proper character handling is that this process is useful for copying and logging random chunks of text from web pages, but if common characters like single quotes are not handled as expected, confidence in the system is much reduced.

Display big numbers in terminal

tmux can display big time like the picture below,
is there any way to display big numbers like that,
for example I want to show number of users in real time.
To the extent of my knowledge, there is no such feature in tmux. You could use watch (part of the procps tools) and figlet to implement such a feature:
watch runs a command periodically and prints the output on the screen. It always clears the screen before running the command.
figlet renders a string in a ASCII-Art style font. There a several fonts availiable.
So for instance you could show the number of users on a system (at least on Linux) using the following command line:
watch "who | wc -l | figlet -f big"
Unfortunatly the text won't be centered, as it is with clock-mode.

disable automatic line wrapping in Ubuntu terminal

I used some sql command to join two tables and the result was two terminal line long for each row of resulted table.
I dont want so ... i mean is there any way to get scroll bar at the bottom so that a row can be fit into a terminal line. and it will be a well structured and readable output
I hope you get my question.
There is no way on a standard terminal. You could use e.g. less as your pager for you sql-client.
I propose to pipe the output into the command less -S:
$ mysql-command-doing-the-SELECT | less -S
(To achieve this in the interactive mysql console, you can type pager less -S.)
Then all lines are displayed without being wrapped, and you can scroll sideways using the arrow keys. You can also use the command less (without the option -S) and then interactively type - S to achieve the non-wrapping. (Type again to toggle.)
If you need a real scroll bar, I propose to pipe the output into a real file and then use a more sophisticated program like gedit (which can be switched to a non-wrapping display) to display it with a decent scroll bar.
Another solution: copy the data from the terminal and paste it into your favorite editor. The copied text will not have any line breaks "\n".
(Offtopic: on a linux system you can just select the text with a mouse and mouse-middle-click in your editor. This will copy the text without filling out the main copy-paste buffer.)

load linux screen setups from file

I use linux screen heavily , generally if the OS didn't restart or say as long as the SCREEN process is there, I can re-attach to my terminals.
But I don't want to set-up the screens each time after my computer restarts that's tedious work.
so I generally setup a series of screens to run different categories of command
1. create a window, rename the screen, run specific command
2. etc...
Is there a way to create these screen setups automatically , say can I script to do that ?
Edit: what is more important here is how to paste some command into the window after the window is created.
Yes, of course.
You just need to specify the configuration of screen in ~/.screenrc.
If you want to use several configurations, you can create several config files
and start screens with -c key.
screen -c ~/.screenrc1
screen -c ~/.screenrc2
screen -c ~/.screenrc3
Example of ~/.screenrc:
screen -t news 8 newsbeuter
screen -t jabber 9 freetalk
here will be open two windows: on 8 -- newsbeuter (the name of the window news); on 9 — freetalk (the name of the window jabber).

Linux(Ubuntu) Terminal-how to view previous pages not visible anymore

When you scroll up, say to see a log, the first portion of it will not be visible since the terminal only supports a limited no. of lines. So if you want to scroll up and be able to see everything, at least a few pages up, how do you do it?
Use Shift+Page Up and Shift+Page Down.
Piping the output to a pager like the following is a better choice:
command | less
command | more
You can enable unlimited scroll back (or a huge amount if you want).
To do this, go to
File → Profile preferences → Scrolling [tab]
Then, check Unlimited, or set the number of lines desired. And of course, it only applies to the next typed lines.
Some tricks I use-
some terminal applications (gnome-terminal) allow you to increase the scroll-back buffer size
pipe output to a file:
command > file.log
pipe your command to less:
command | less
tail log and pipe to grep to reduce output
tail -f example.log | grep 'search text'
An alternative to screen is using tee to copy all output to a file while still printing it on the terminal:
yourcommand | tee output.txt
Try using the screen command, and set its scrollback buffer to a larger size.
screen has many other benefits and wonderful features.
If all you're doing is looking at a log, you could alternately use a pager such as less
If you want to scroll line by line, you can use
Control+Shift+Up/Down Arrows.
If you are using gnome-term (the default), then you can change your settings. Either set the no. of lines to unlimited, or to a much larger buffer size than the default.
Essentially seconding to #zerick's solution but if you're on gnome-terminal you can modify its config. See this.
If you are in tmux (can create multiple terminal sessions in a single terminal session, highly recommended), you can easily use your normal navigation keys to scroll around after you do Ctrl-b then [, for more details let's take a look at: How do I scroll in tmux?
None of these answer the original question. All answers are how to make new terminal windows (or current one) start behaving a certain way. The question is about how to see whats already scrolled away.
To answer this, each terminal session should have it's own "history" file (not to be confused with what command history is) containing all the stuff that relates to stdin/stdout displayed. I could be wrong but this may be different depending on the terminal emulator you use. Some just trash it when you close the window/ end the session.
I am trying to get this figured out myself so here is the more direct answer in a different thread.
https://unix.stackexchange.com/questions/145050/what-exactly-is-scrollback-and-scrollback-buffer
From what this tells me, I suspect best advice you can get is, for whatever terminal emulator you use, look for where it stores the scrollback buffer and that might be your only hope. It's what I am going to try right now. (and that is IF the session is currently still open, not closed terminal windows)

Resources