Many Unix files are text files. This may seem simplistic, but it’s actually very powerful. Text files are easy to create, read, and manipulate. Many Unix commands are for working with text files.
The first category of Unix commands for working with text files might be called “text viewers”. These includes commands such as cat, head, tail, more, and less. All of these commands are used by typing the command plus the name of a file.
cat — Short for “concatenate”, this command is used to temporarily combine files. But if you use it on only one file, it just displays the file to the screen.
head — This command shows the first 10 lines of a file. (You can adjust the number of lines using the flag -n.)
tail — This command shows the last 10 lines of a file. (You can also use -n here to show more lines.)
more — Like cat, this shows the entire contents of a file, but prompts you for “more?” between each page. Hit the space bar to go to the next page, or use the up and down arrows. Hit “q” to quit.
less — This is another “pager” like more, i.e. it shows one page at a time. It was meant to be a successor or alternative to more and was hence given the opposite name less. It had more features than more (sounds like an Abbott and Costello routine) when it first came out, but now the two commands are about the same.
Here are some examples:
How to view your hosts file, where you can map host names to IP addresses:
cat /etc/hosts
If you have Personal Web Sharing turned on, how to view the last 10 lines of the Apache log file:
tail /var/log/httpd/access_log
How to read the Apache configuration file, one page at a time:
more /etc/httpd/httpd.conf