17.4 Identifying and Working with File Types 263
head <filename>
Head can be useful, but because it’s limited to the first several lines, you won’t know how long the
file actually is. By default, you can only read the first10linesofafile, although we can specify the
numbertoseemorebytyping:
head -20 <filename>
Read head’s man page (man head) for more information. You’ll probably find that less or more
are more helpful, because you can page through the file if you find that the information you’re look-
ing for is further into the file than you originally thought.
The tail Command
The reverse of head (obviously), is tail.With(tail), you can review the last 10 lines of a file.
The cat Command
The command cat, short for concatenation, will dump the contents of the entire file on the screen.
Using cat can be handy if the file is fairly short, such as when we created sneakers.txt.Butifa
file is fairly long, it will easily scroll past you on the screen, since cat displays the whole file.
The grep Command
The grep command is pretty nifty for finding specific character strings in a file. Let’s say we want to
find every reference we made to “coffee” in the file sneakers.txt, which we created in our login
directory. We could type:
grep coffee sneakers.txt
andwewouldseeeverylineinwhichtheword“coffee” could be found.
Tip: Unless otherwise specified, grep searches are case sensitive. That means that
searching for Coffee is different than searching for coffee.Soamonggrep’s options is -i,
which allows you to make a case-insensitive search through a file. Read the grep man
page for more about this command.
Comments to this Manuals