2.4. Inspecting Files¶
2.4.1. cat
¶
One quick way to display the contents of a regular file to standard output
is using the cat
(concatenate [to standard output]) command, supplying
a path to the file you want to view as a command-line argument.
cd ~/cs1302-unix/books
cat sherlock_holmes.txt
2.4.2. less
¶
The cat
command displays the entire contents of a file all at once,
which may not be desirable for large files. To display the contents of
a regular file one page (or screen) at a time, use the less
command
and supply a path to the file you want to view as a command-line argument.
To quit out of less
, press the q
key. To move up and down one
page (screen) at a time, use the C-v
and M-v
shortcuts,
respectively.
cd
less cs1302-unix/books/moby_dick.txt
Try this!
We have not discussed the head
and tail
commands. Try them
alongside the cat
and less
examples to discover what they
do. If you can’t figure out based on what you see, consider using
some commands to get help directly in the terminal.