Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Opening Large Files

Discussion in 'General Discussion' started by Jeff75, Oct 29, 2003.

  1. Jeff75

    Jeff75 Well-Known Member

    Apr 11, 2003
    Likes Received:
    Trophy Points:
    I need to view part of a large file (over 100 MBs) and was wondering if there's anyway that I can just view the first 50 lines or so at the very top or very bottom of the file. If so, can somebody let me know what command to use?

    Also, if I need to edit the file, is there anyway to do this by only editing the first or last few lines of the file? If I try to open the entire thing, it takes forever and never ends up letting me edit the file.
  2. christi1

    christi1 Well-Known Member

    Oct 20, 2003
    Likes Received:
    Trophy Points:
    Texas, USA
    Try this:

    Creat a file named viewer.php and copy/paste the following into it:

    // number of lines to show
    $lines = "50";

    // define our starting count
    $count = "0";

    // open the file
    $fp = fopen ("/path/to/your/file.txt", "r");
    $buffer = fread($fp, 100000);
    fclose ($fp);
    $stuff = explode("\n", "$buffer");

    if(is_array($stuff)) {
    foreach($stuff as $line) {
    // we don't want to count empty lines, so...
    if($line != "") {
    // if the line number is less than the number of lines you stated above, print it
    if($count < $lines) {
    echo "$line<br>\n";

    That will open your file (provided you have access to do so) and print the first 50 lines for you. Can change the 50 to however many lines you want to see.
    #2 christi1, Oct 29, 2003
    Last edited: Oct 29, 2003
  3. ciphervendor

    ciphervendor Well-Known Member

    Aug 26, 2002
    Likes Received:
    Trophy Points:
    vi/vim is super efficient as well. Whatever you do, do not use pico ;)
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice