LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 04-16-2011, 02:40 PM   #1
vinodvb
LQ Newbie
 
Registered: Dec 2010
Location: Bangalore
Distribution: RHEL
Posts: 25

Rep: Reputation: 6
Question cat command to behave like more or less


hello all....is there any way by which the cat command can be made to behave like less or more?

i.e when less or more used with a text file as argument, will display the file 1 page at a time, allowing us to navigate through the file.

So any way for cat to display the file 1 page at a time?

P.S : I don't want to pipe the output of cat to less or more.

Regards,
Vinod
 
Old 04-16-2011, 02:48 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

Why can't you use less or more instead of cat?
 
Old 04-16-2011, 02:53 PM   #3
vinodvb
LQ Newbie
 
Registered: Dec 2010
Location: Bangalore
Distribution: RHEL
Posts: 25

Original Poster
Rep: Reputation: 6
I know less or more will do the job.
but curious to know if cat can get the job done.

more command creates a NOECHO environment.
So would like to know the way by which cat can be made to behave like more or less.
 
Old 04-16-2011, 02:54 PM   #4
themanwhowas
Member
 
Registered: Nov 2005
Distribution: CentOS 5, BT5, Slackware 12.0
Posts: 207

Rep: Reputation: 29
instead of "cat ./text.txt" use "less ./text.txt". more is often a symlink to less. If you still want cat to run as less, you can create an alias. "alias cat=less". I don't know why you would do that though
 
Old 04-16-2011, 02:59 PM   #5
vinodvb
LQ Newbie
 
Registered: Dec 2010
Location: Bangalore
Distribution: RHEL
Posts: 25

Original Poster
Rep: Reputation: 6
this was one of the questions I was asked during an interview.
I was wondering if there is a way for cat to behave like less or more on its own.
 
Old 04-16-2011, 03:09 PM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

Too my knowledge, cat does not have an option to show content page by page (I don't think it was ever designed to do so).

A lot of people do the following : cat file | more This is, strictly speaking, not wrong, but it is a waste of resources, more file is all it takes (2 commands and a pipe vs one command).

There are probably solutions without using more or less, but they all involve piping the output of the cat command to another (set of) programme(s).
 
1 members found this post helpful.
Old 04-16-2011, 03:11 PM   #7
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
Question


http://www.gnu.org/software/coreutil...cat-invocation

I can't think of any way to do this without processing cat's output through some other command or shell script.

The question doesn't even make sense. The purpose of cat is to concatenate files, not to page them.

Edit
Some terminals support Ctrl-s/Ctrl-q to pause and resume output. One must be very quick on the keys, especially on modern hardware. Might this count as an answer?

Maybe cat's output could be directed at some buffered stream device in /dev. You'd still need some way to signal the device to flush its buffer to the terminal and then resume accepting input. I have no clue how one would even begin!

Last edited by Telengard; 04-16-2011 at 03:26 PM. Reason: fix formatting
 
Old 04-16-2011, 03:27 PM   #8
GVrooman
Member
 
Registered: May 2008
Distribution: Slackware
Posts: 38

Rep: Reputation: 11
Not according to the man page, but there is always pg. On some systems you could use Ctl-S to freeze the screen, but it doesn't seem to work in Linux.
 
Old 04-16-2011, 03:35 PM   #9
vinodvb
LQ Newbie
 
Registered: Dec 2010
Location: Bangalore
Distribution: RHEL
Posts: 25

Original Poster
Rep: Reputation: 6
Thank you all for the response. I guess alias is the way (atleast without much complication)
 
Old 04-16-2011, 04:08 PM   #10
GVrooman
Member
 
Registered: May 2008
Distribution: Slackware
Posts: 38

Rep: Reputation: 11
I just checked. Ctl-S / Ctl-Q won't work in Konsole, but if you leave X altogether and go to the command line, it works fine.
 
Old 04-16-2011, 08:14 PM   #11
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
Quote:
Originally Posted by GVrooman View Post
I just checked. Ctl-S / Ctl-Q won't work in Konsole, but if you leave X altogether and go to the command line, it works fine.
Actually my version of Konsole has a setting for this.

Settings -> Configure Konsole -> General -> Misc -> Use Ctrl+S/Ctrl+Q flow control

Code:
foo$ konsole --version
Qt: 3.3.8b
KDE: 3.5.10
Konsole: 1.6.6
foo$
Edit
Yeah, it works

Last edited by Telengard; 04-16-2011 at 08:22 PM. Reason: more detail
 
Old 04-16-2011, 08:25 PM   #12
GVrooman
Member
 
Registered: May 2008
Distribution: Slackware
Posts: 38

Rep: Reputation: 11
Quote:
Originally Posted by Telengard View Post
Actually my version of Konsole has a setting for this.

Settings -> Configure Konsole -> General -> Misc -> Use Ctrl+S/Ctrl+Q flow control

Code:
foo$ konsole --version
Qt: 3.3.8b
KDE: 3.5.10
Konsole: 1.6.6
foo$
You are absolutely right. You learn something new every day.
 
  


Reply

Tags
cat, pager


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cat command confusion. nnjond Linux - Newbie 6 08-12-2010 10:16 AM
Cat command Option foysol_bgd Linux - Newbie 5 12-11-2008 11:33 AM
CAT Command ouncya Linux - Newbie 11 08-26-2007 12:48 AM
cat command juanb Linux - Newbie 4 08-19-2004 12:14 PM
cat Command Moeses Linux - General 1 06-20-2002 04:27 AM


All times are GMT -5. The time now is 11:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration