0

Is there any way to print the last printed lines on a linux terminal? I'm trying to run a command that does that on my node app so that i can parse that content. Is all the shell content logged in a file, or something like that?

I want to echo the console own content. Get the last outputs of the own terminal.

I dont want command outputs I want to get console.logs() and console.errs()

Miguel Morujão
  • 1,131
  • 1
  • 14
  • 39
  • What do you mean by "last printed line"? A shell may return multiple lines or none when executing a command. – Panther Coder Mar 17 '17 at 16:01
  • I want to get the shell content. For example console.logs() of my runings app or exeptions. So that i can parse it – Miguel Morujão Mar 17 '17 at 16:07
  • 1
    ...so, here's the thing -- that's *terminal* content, not *shell* content. Something that was written by a command you ran, unless its output was redirected with a command substitution or the like, goes straight to the terminal itself; the shell never sees it. – Charles Duffy Mar 17 '17 at 16:31
  • 1
    You can demonstrate this yourself on Linux: If you run `ls -l /proc/self/fd/ /proc/$$/fd/`, you'll note that FD 0, FD 1 and FD 2 (stdin, stdout, and stderr) point to exactly the same place for both `ls` (as determined by the output for the `/proc/self/fd` directory) and the shell itself (as determined by the output for the `/proc/$$/fd` directory). – Charles Duffy Mar 17 '17 at 16:33
  • 1
    ...as for your `console.logs()` and `console.errs()`, that's a concept that neither shells nor terminals share -- you'd have to look up exactly what Node does with them. If it's written to stdout or stderr, though, all of the above applies -- the only difference with the answers this is marked as duplicative of in the latter case is that there might be some extra redirection (ie. `2>&1`) required, but we *do* have questions and answers covering how to capture stderr already (I'll add one to the duplicate list, if you like). – Charles Duffy Mar 17 '17 at 16:35
  • 1
    BTW, **if you're asking about a specific terminal** (or asking a question in such a way as to let an answer specify a specific terminal to use), we might be able to help you more. A question asking how to capture output previously written to a command in `tmux`, for instance, is very likely to have an answer. – Charles Duffy Mar 17 '17 at 16:38
  • @CharlesDuffy Thanks, for the help. I'm using the ubuntu default terminal. I think the answer to my problem is here : https://nodejs.org/api/process.html#process_process_stderr – Miguel Morujão Mar 17 '17 at 16:43
  • 1
    Yup -- that documentation makes it clear that `console.logs()` goes to stdout and `console.errs()` goes to stderr, so you can use `>file` or `| tee file` to redirect the former, and can merge the latter with it via `>&1`, copy it through a separate log with something like `2> >(tee file.err >&1)`, etc. – Charles Duffy Mar 17 '17 at 16:45

2 Answers2

1

You need to save it by urself. There are history option for Command you used but not for output unless it has been saved by other program in case of error.

error404
  • 331
  • 1
  • 8
0

You can use top command. It tells a lot much information regarding the system. You can use ps command and get the information about running processes and then use cat command to store that output in some other file or you can even use pipeline symbol to redirect its output to some file.

Aniruddh Agarwal
  • 900
  • 1
  • 7
  • 22
  • `top` does indeed have a lot of information, but that information does not include content written to the terminal by previously-invoked, now-completed commands. – Charles Duffy Mar 17 '17 at 16:36