File Contents

In the last section we looked at listing files and directories with the ls command. In this section we will look at the cat and wc commands. The cat command lets you view the contents of a file. The wc command gives you information about the number of words and lines in a file.

cat

To view the contents of a file, we can use the cat (short for concatenate) command as follows:

cat [opts] file1 ... fileN
						

Here opts are one or more of the options understood by cat, and file1...fileN are the names of the files whose contents should be printed. The options, opts, are optional and can be omitted. Two commonly used options are discussed later in this section.

The following example illustrates the use of cat:

$ cat fruits

This command ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.