"more", "head" and "cat" - Read Files

This section provides a tutorial example on how to use 'more', 'head' or 'tail' commands to read text files one screen at a time, to read the first 10 lines, or to read the last 10 lines.

If you have a text file, you read its content in different ways using "more", "head" and "tail" commands. Here are some examples:

1. Read a text file one screen at a time using the "more" command.

herong$ more history-of-linux.txt

History of Linux

In April, 1991, Linus Torvalds, a
21-years old student on computer
science at the University of Helsinki,
Finland, began his personal project—to
create a new operating system kernel.
This modest project will evolve to the
world famous Linux operating system and
will make Linus one of the most
influential people in the world of
technology today.

Linus Benedict Torvalds (St Linus was
the second pope, 64-76 AD) was born on
December 28, 1969 in Helsinki, Finland.
He is the son of Nils and Anna
Torvalds. Nils was a reporter, Ana was
a translator, but both pursued careers
in journalism. Torvalds's grandfather
was a noted Finnish poet, Ole Torvalds
(1916–1995). His parents divorced when
Linus was young, and he was raised by
his mother and grandparents. The
Torvalds family belongs to the
Swedish-speaking minority in Finland,
which numbers about 300000.

:h

At the end of each screen, "more" prompts you for the next sub-command. Here is a list of commonly used "more" sub-commands:

q          Quit
h          Help
b          Move backward one screen
f          Move forward one screen
/pattern - Search for a pattern
/          Repeat the last search
?pattern - Search backward
?          Repeat the last search backward

2. Read the first 10 lines of a text file using the "head" command. If you want to read the first 20 lines, use "head -20" command.

herong$ head history-of-linux.txt

History of Linux

In April, 1991, Linus Torvalds, a
21-years old student on computer
science at the University of Helsinki,
Finland, began his personal project—to
create a new operating system kernel.
This modest project will evolve to the
world famous Linux operating system and
will make Linus one of the most

3. Read the last 10 lines of a text file using the "tail" command. If you want to read the last 20 lines, use "tail -20" command.

herong$ head history-of-linux.txt

mid-1970s, Toerngvist bought one of the
first personal computers, a Commodore
Vic 20. Linus soon became bored with
the few programs that were available
for it, and by the time he was 10, he
thus began to create new ones, first
using the BASIC programming language
and then using the much more difficult
but also more powerful assembly
language.

Table of Contents

 About This Book

 Introduction to Linux Systems

 Cockpit - Web Portal for Administrator

 Process Management

Files and Directories

 "find" - Search for Files

"more", "head" and "cat" - Read Files

 "split" and "cat" - Split and Join Files

 Truncate Log Files

 "compress/uncompress" - Compressed *.Z Files

 "gzip/gunzip" - Compressed *.gz Files

 "xz/unxz" - Compressed *.xz or *.lzma Files

 "tar -c" and "tar -x" - Create and Extract Archive Files

 "zip" and "unzip" - Create and Extract ZIP Files

 "Operation not permitted" Error on macOS

 Users and Groups

 File Systems

 Block Devices and Partitions

 LVM (Logical Volume Manager)

 Installing CentOS

 SELinux - Security-Enhanced Linux

 Network Connection on CentOS

 Internet Networking Tools

 SSH Protocol and ssh/scp Commands

 Software Package Manager on CentOS - DNF and YUM

 vsftpd - Very Secure FTP Daemon

 LDAP (Lightweight Directory Access Protocol)

 Administrative Tasks

 References

 Full Version in PDF/EPUB