APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

How to view large files without more or less

© July 2013 Tony Lawrence

I have a rescue disk that doesn't include "more" or "less" - how can I examine large files?

I'd say to get a better rescue disk, but maybe this is some ancient SCO Unix system where you are lucky to have anything at all, so let's see what can be done.

Just two quick things first: are you sure you aren't just using a bad $PATH? Would a "chroot" to the hard drive help? NO? OK, then..

I suppose if you don't have "more", you probably don't have "vi", "vim", or "view" either, right?

Maybe you have "ed" or "sed"?

$ ed logs/access.log
.. lines from the file
$ sed -n '25,50p' logs/access.log

You can try being quick with CTRL-S. If that will work for you, you might want to do "stty -ixany" so that you have to use CTRL-Q to restart output.

Maybe read it on paper?

cat /var/log/messages > /dev/lp0 

Watch out for line endings - if this is a Unix file and the printer is not doing CR/LF translation, you'll get stair-stepped output. Echoing Escape-&k2G to a HP Laserjet will fix that. I think every printer has some way to do that, but it could require dip switches. You can change "stty onlcr opost" in a script to avoid that, but that won't work for a network printer. You can translate on the fly with "sed" :

sed 's/$/\r/' /var/log/messages > /dev/lp0

You could split it into pieces and look at them separately:

cd /tmp
split -l 24 /var/log/syslog
for i in xa*
  cat i
  echo "press enter for next"
  read ak

Do I need to remind you that if you know what you are looking for "grep" might work?

Good old dd can (clumsily) print out parts of files.

dd if=/var/log/syslog count=1
dd if=/var/log/syslog count=1 skip=1

Would just slowing things down be enough?

while read line
 do echo "$line"
 sleep 1

Or this slightly more complex script:

while read line
 do echo $line
 : $((x=$x+1)) 
 stop=$(($x % 24))
 if [ $stop -lt 1 ]
  echo "Continue?";
  read ak < /dev/tty

That's a Bash version, for "sh" you'd need to do:

 x=`expr $x + 1`
 stop=`expr $x % 24`

By the way, if you are trying to fix the poor machine, the possible loss of "vi" means it's time to brush up on "ed" and "sed". Yeah, I know: not fun, but if that's all you have..

If you have even less than that, it's time to get very creative:

# assuming you need to change line 6 of a file
sed -n '1,5p' /etc/resolv.conf > /tmp/a
echo "Nameserver" > /tmp/b
sed -n '7,$p' /etc/resolv.conf > /tmp/c
cat /tmp/[a-c] > /etc/resolv.conf

Though very clumsy, "dd" can edit text files in a similar way.

So, while not necessarily ideal, you can survive without "more" or "less" - more or less :-)

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> View large files without more or less

Inexpensive and informative Apple related e-books:

El Capitan: A Take Control Crash Course

Take Control of Upgrading to El Capitan

iOS 10: A Take Control Crash Course

Are Your Bits Flipped?

Photos for Mac: A Take Control Crash Course

More Articles by © Tony Lawrence

Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Printer Friendly Version

I think a nerd is a person who uses the telephone to talk to other people about telephones. And a computer nerd therefore is somebody who uses a computer in order to use a computer. (Douglas Adams)

Linux posts

Troubleshooting posts

This post tagged:






Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode