It seems that the purpose of
cat is to concatenate several files. However, many people still use
cat instead of
less (or a similar program like
more) to display a file. See, for example, the GNU m4 manual and the answer "How can I display the contents of a text file on the command line?".
Man page: less
-F or --quit-if-one-screen
lessto automatically exit if the entire file can be displayed on the first screen.
-X or --no-init
Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen.
Nowadays, is it a good practice to use
cat to display or view a file? Why use
cat to view a file?
This makes me think to Useless Use Of Cat.
Note: This question is not about the differences between
more. Moreover, it concerns the visualization of a file created earlier.
According to the answers and comments, it seems that
cat is used beyond its use because it is easier to use than a pager (e.g.
less...). Some people think this is an irrelevant fact (or useless) but experience shows that various subtleties pertaining to the shell may have practical consequences: use a shell loop to process a text file, use unquoted variables...
Negative consequences vary in intensity. For example,
cat foo bar | less is valid because the user concatenates two files but
cat foo | less is not valid. In the same spirit,
cat seems to be required in "a pipeline" although it seems that a pager like
less works in a pipeline too (note:
less is not suited in all cases concerning displaying, e.g. Reading a named pipe: tail or cat?).
See also: How to cat a file with "or" options
catis easier: how many keystrokes do you need to type
catyou can continue your work in the same terminal and the output is still visible to lookup something, copy & paste etc.
-X, otherwise I don't see anything for small files...
cat | blahis "correct" in general practice is just fanning the flames for another pointless FOSS Holy War.