Is there ever a reason to use `cat` when you've got `less`?
Although both commands allow you to view the content of a file, their original purposes are quite different.
less extends the capabilities of more. The latter was created to view the content of a file one screenful at a time. less adds features such as backward movements and better memory management (no need to read the entire file before being able to see the first lines).
cat concatenates files and prints the result on the standard output. If you provide only one file, you will see the content of that file. It becomes 'powerful' when you provide multiple files. A good example is the combination of split and cat. The first command will divide a large file in small portions. The second one will then concatenate the small portions into a single file.
Back to your question, cat would be preferred in an autonomous script requiring files to be read entirely (or concatenated) without interaction. In terms of file viewing, I think it's more a question of taste.
I usually use cat
when I need to type a command based on something in the file. cat
is more convenient since you can see the file (if it's small) while you have access to the shell prompt. It also allows for pipe lining.
I personally prefer view
for static content or tail -f
for dynamic content.
This does not answer your question, though. There is a saying "why use more if you have less" ;-)
But there are cases where I prefer cat to less: I usually work with X11-windows. These windows have a scroll-buffer which can be set to some hundred lines.
Doing a cat
for - let's say 200 lines and then using the mouse with the scroll-bar is more comfortable to me than using less
in these cases.