[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Command line: How do you keep the output from scrolling out of sight?

on 10:59 Tue 01 Mar, Jason Hsu (jhsu802701@jasonhsu.com) wrote:
> I'm using Debian in a command-line-only installation for running a
> firewall/server.
> I know that I'm supposed to use the messages I see every time I enter
> a command for troubleshooting purposes.  But if the output is too
> long, then the first messages scroll out of sight, and that makes it
> impossible to properly troubleshoot when I don't know what I'm doing.
> Is there a way to get the output to temporarily stop so I can read it
> all if I wish?

As others have noted:

   command | less

Or an alternate pager, from least to most featured: pg, more, most, dog.
You can specify this with the PAGER environment variable or under
/etc/alternatives/pager (see update-alternatives).

You can dump output to a file.  Several varaints:

    command >myfile       # save standard output
    command >myfile 2>&1  # save standard output & standard error
    command >myfile 2>myfile.err  # separate stdout/stderr
    command >/dev/null    # discard stdout (stderr displayed to terminal)
    command | tee myfile  # view output, save stdout to 'myfile'
    command 2>&1 | tee myfile # view output, both stdout & stderr to 'myfile'

Your terminal's scrollbar should be generally useful.  Set a
sufficiently large scrollback buffer.

Page-up / page-down, may work in some terminals and/or console.

The 'script' command can be used to record interactive sessions.
Depending on the amount of screen-painting going on (ncurses /
full-screen terminal programs such as top, etc.), this may not be too
readable.  'scriptreplay' may make for a saner output.

Using 'screen' one of the benefits is a scrollback buffer.  Very handy.

For noninteractive comamnds, where I want to massage the output but
don't know what filters I need to use immediately (or want to see
intermediate results):

    command | vim -   # read stdout into vim for interactive editing.

I can then annotate or use futher regex substitutions or commands to
clean up / modify data.

Mostly I just pipe output to less or redirect to a file as needed.

Dr. Ed Morbius, Chief Scientist /            |
  Robot Wrangler / Staff Psychologist        | When you seek unlimited power
Krell Power Systems Unlimited                |                  Go to Krell!

Reply to: