How to get and copy a too long output completely in terminal?

856

Solution 1

I know in the xfce4-terminal there is a option to increase the number of lines shown:

enter image description here

For ubuntu Terminal enter image description here

Aside from that there is what @Zelda64fan said.

Solution 2

You could send the output to a file: command > file.txt (where command is the command you want to run and file.txt is the file you want to save it to) and then view it with gedit file.txt.

Solution 3

Use xclip

cat long.output | xclip -sel clip

If not installed you can do

sudo apt-get install xclip

Solution 4

If you don't need the entire output, you could pipe it through less: command | less. This would also save the bother of having to delete the file once you've reviewed the output.

Solution 5

Save console output into a file:

  1. tee command

tee command - read from standard input and write to standard output and files.

It automatically creates file and save, all the output of cmd ps -ax into a file named as processes_info in the same folder from where the cmd has run.

user@admin:~$ ps -ax | tee processes_info
  1. script command

script command - make typescript of terminal session.

user@admin:~$ script my_console_output.txt

This creates a file named as my_console_output.txt and will open a subshell and records all information through this session. After this, script get started and whatever the console output, it will get stored in the file my_console_output.txt; unless and until the script ends when the forked shell exits. (e.g., when the user types exit or when CTRLD is typed.)

user@admin:~$ script -c "ps ax" processes_info.txt
  • it starts the script;

  • creates the file processes_info.txt;

  • stores the console output into the file;

  • end (close) the script.

    Other example:

     script -c 'echo "Hello, World!"' hello.txt
    
Share:
856

Related videos on Youtube

James Gayle
Author by

James Gayle

Updated on September 18, 2022

Comments

  • James Gayle
    James Gayle over 1 year

    i have a button on my index / home page:

    <a href="action.php">click</a>
    

    When this is clicked it runs my mysql query in action.php and after i have run my query i want to send out an email. So after the query has executed i include my send_email.php file:

    $query = "update table1 SET action = '1' WHERE something = something";
    $result = mysql_query($query);
    
    include 'send email.php'
    

    in send_email.php i have:

    <?php
    date_default_timezone_set("Europe/London");
    // multiple recipients
    $to  = "[email protected]"; // 
    
    // subject
    $subject = 'New Supplier Set-Up - Hewden Portal';
    
    // message
    $message = include '../../assets/email/index.php';
    
    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    // Additional headers
    $headers .= 'To: Mark <[email protected]>'. "\r\n";
    $headers .= 'From: Hewden Portal <[email protected]>' . "\r\n";
    $headers .= "Cc: mark.o'[email protected]" . "\r\n";
    
    
    // Mail it
    mail($to, $subject, $message, $headers);
    
    echo "Updated data successfully\n";
    
    ?>
    

    As you can see I am trying to include my email html as a seperate php file stored in assets/email/index.php. i am trying to do it this way so the email can be easily edited at a later date.

    However using this method doesnt work. The email is sent but its blank without any HTML. Also after the query has executed it takes you to the email html page/index.php.

    an illustration of my email html / index.php:

    <html>
    <Body>
    <p>This is my email template</p>
    <p>More Text here bla bla</p>
    <style>
    Some CSS
    </style>
    </body>
    </html>
    

    Why is this? when it should be echoing 'Updated data Succesfully' and be sending the email with html?

    Can someone please show me what i am doing wrong? Thanks

  • 22lk94k943 only
    22lk94k943 only almost 11 years
    +1 Pipe and tee are not optimal as dont work on few cases like take in a HROOT 3NVIORTNM3NT
  • Sparhawk
    Sparhawk about 10 years
    less output is pretty hard to copy.
  • James Gayle
    James Gayle about 9 years
    yes thats correct, how would i structure this using file_get_contents please as this is something i have never used before, thanks
  • Richie
    Richie about 9 years
    It's well covered in the documentation. Click the provided link above
  • James Gayle
    James Gayle about 9 years
    thanks i have done what you suggested using $message = file_get_contents('../../assets/email/index.php'); however now the email will not send
  • Richie
    Richie about 9 years
    Let me see what's in that file?
  • Sergiy Kolodyazhnyy
    Sergiy Kolodyazhnyy over 7 years
    This one is my personal favorite for GUI terminals. With TTY it won't work, unfortunately, only redirection to a file will help there
  • Jignesh Gohel
    Jignesh Gohel about 6 years
    script -c "rails runner -e development lib/scripts/my_script.rb" report.txt helped me to capture a Rails runner script's very-very long output easily to a file. I tried using redirecting to a file but it got written only at the end of script. That didn't helped me because I had few interactive commands in my script. Then I used just script on my and then ran the rails runner in script session but it didn't wrote everything. Then I found this script -c "runner command here" output_file and it saved all the output as was desired. This was on Ubuntu 14.04 LTS