cat a quick reader, more medium navigator, and less full-featured experience. Let's look into the clear difference between cat, more and less command.
2. cat Command
The cat command is commonly used to have a quick view of small file contents. It is part of the POSIX standard so available in Unix-like systems. The cat command outputs the full content of the file to the terminal - doesn't support a way to scroll up or down. Otherwise, you need to use a mouse to scroll up and down using the terminal scroll bar feature. As its output the entire content, when viewing large file it is not that convenient.
$ cat /etc/ssh/ssh_config
In the output, you can see cat command spit the entire content to the terminal. You need to use the scroll bar to navigate.
Apart from viewing you can use the cat command for file creation, concatenation (combining two or more files and printing to stdout), appending, displaying line numbers, squeezing blank lines, and showing non-printing characters. Another place cat comes useful is in scripting where we can concatenate multiple files. That is to use file contents as input to other commands or scripts.
3. more Command
The more command allows viewing the contents of a file by one screen at a time. That means it stops displaying when it fills one screen. At the bottom, it shows the percentage (%) of the entire file content it has shown so far. More command allows a few navigations such as next page, next line, and go back one page.
- Space: Display the next page
- Enter: Display the next line
- b: Go back one page
- q: Quit
$ more /etc/ssh/ssh_config
4. less command
The less command has more featured when compared to more. It is advanced pager for file viewing.
Similar to more it displays file contents in one screenful at a time. The main attraction of less command is that it supports both forward and backward navigation. Obviously best for viewing large files.
Other than this it supports line numbers, searching strings, marking positions, and viewing multiple files.
$ more /etc/ssh/ssh_config
Useful navigation shortcuts to use with less:
- Space: Forward one screen.
- b: Backward one screen.
- Enter or Down Arrow: Forward one line.
- Up Arrow: Backward one line.
- G: Move to the end of the text file.
- g: Move to the beginning of the text file.
- /:pattern: Search for a pattern going forward.
- ?:pattern: Search for a pattern going backward.
- n: Repeat the previous search.
- N: Repeat the previous search, but in the reverse direction.
- q or Q: Quit within less.
5. Comparing cat, more, and less
cat is a good tool to have a quick overview of short files. Useful in scripting for the concatenation of multiple files and is often used in conjunction with other commands such grep.
When compared with cat better for viewing large files and supporting forward navigation.
Less command is a feature-rich and advanced version of more command. As support backward and forward navigation best for viewing large files.
|Show Line number
|Yes - Only forward